Hej Ronny
Jeg fik skrev forkert i min php kode den rigtige er her:
- $antal = 0;
- if (isset($_POST['postal_1']) && ($_POST['postal_2'])) {
- $postal_1 = ($_POST['postal_1']);
- $postal_2 = ($_POST['postal_2']);
- $stmt_row = $DBH->query("SELECT * from XXX where upgraded = '0' AND postal BETWEEN $postal_1 AND $postal_2");
- $stmt_row->execute();
- if ($antal >= 1) {
- while ($row = $stmt_row->fetch()) {
- $adresse = "'".$row['name'].", ".$row['address'].",".$row['postal'].",".$row['city']."',";
- var locate = <?php echo json_encode( $adresse ) ?>;
- var locations = [locate];
Det virker
Hele mit script er her, ligger ikke en demo op da adresserne i min db er reelle kunder.
Scriptet er nok lidt "knoldet" men det virker. Dog kommer der kun max 11 markers frem på mit google map selvom der er langt flere poster???
- <?php
- session_start();
- require_once ("config.php");
- $order = "postal";
-
- $antal = 0;
- if (isset($_POST['postal_1']) && ($_POST['postal_2'])) {
- $postal_1 = ($_POST['postal_1']);
- $postal_2 = ($_POST['postal_2']);
- $stmt_row = $DBH->query("SELECT * from XXX where upgraded = '0' AND postal BETWEEN $postal_1 AND $postal_2");
- $stmt_row->execute();
- $antal = $stmt_row->RowCount();
- $stmt = $DBH->query("SELECT * from XXX where upgraded = '0' AND postal BETWEEN $postal_1 AND $postal_2 order by pl_date");
- $stmt->execute();
- $antal = $stmt->RowCount();
- }
- ?>
- <!DOCTYPE html!">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta charset="UTF-8">
- <title>Route planner</title>
- <link rel="stylesheet" href="css/styles.css" type="text/css" media="Screen" />
- <link rel="stylesheet" href="css/phone.css" type="text/css" media="handheld" />
- <link rel="stylesheet" href="css/print_la.css" type="text/css" media="print" />
- <link rel="shortcut icon" href="css/images/favicon.ico"/>
- <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
- </head>
- <body>
- <div id="wrapper">
- <div id="header">
- <img src="css/images/logo.png" alt="Logo" width="260" height="100" /></div>
- <div id="menu"><?php include_once("css/menu.php"); ?> </div>
- <div id="content">
- <fieldset>
- <legend><p>Search between postals</p></legend>
- <table>
- <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
- <tr>
- <td><p><label>Postal 1:</p><input type="text" name="postal_1" maxlength="4" placeholder="Type postal" autofocus /></label></p></td>
- <td><p><label>Postal 2:</p><input type="text" name="postal_2"maxlength="4" placeholder="Type postal" /></label></p></td>
- <td><br /><input type="submit" value="SEARCH">
- </td>
- </tr>
- </form>
- </table>
- </fieldset>
- <br>
- <div id="map">
- <?php
- if ($antal >= 1) {
- while ($row = $stmt_row->fetch()) {
- $adresse = "'".$row['name'].", ".$row['address'].",".$row['postal'].",".$row['city']."',";
- ?>
- <script type="text/javascript">
- var delay = 100;
- var infowindow = new google.maps.InfoWindow();
- var latlng = new google.maps.LatLng(55.6760968, 12.5683371);
- var mapOptions = {
- zoom: 4,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- }
-
- var geocoder = new google.maps.Geocoder();
- var map = new google.maps.Map(document.getElementById("map"), mapOptions);
- var bounds = new google.maps.LatLngBounds();
-
- function geocodeAddress(address, next) {
- geocoder.geocode({address:address}, function (results,status)
- {
- if (status == google.maps.GeocoderStatus.OK) {
- var p = results[0].geometry.location;
- var lat=p.lat();
- var lng=p.lng();
- createMarker(address,lat,lng);
- }
- else {
- if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {
- nextAddress--;
- delay++;
- } else {
- }
- }
- next();
- }
- );
- }
- function createMarker(add,lat,lng) {
- var contentString = add;
- var marker = new google.maps.Marker({
- position: new google.maps.LatLng(lat,lng),
- map: map,
- });
-
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.setContent(contentString);
- infowindow.open(map,marker);
- });
-
- bounds.extend(marker.position);
- }
- var locate = <?php echo json_encode( $adresse ) ?>;
- var locations = [locate];
- //var locations = [ <?php echo $adresse;?> ];
- //var locations = [ 'stradellasvej 22,2450,københavn SV','tartinisvej 2,2450,københavn SV' ]; Adresser indsættes via mysql
- var nextAddress = 0;
- function theNext() {
- if (nextAddress < locations.length) {
- setTimeout('geocodeAddress("'+locations[nextAddress]+'",theNext)', delay);
- nextAddress++;
- } else {
- map.fitBounds(bounds);
- }
- }
- theNext();
- </script>
- <?php } } ?>
- </div>
- <div id="right">
- <?php ECHO "antal enheder: ".$antal;
- if ($antal >= 1) {
- while ($row_2 = $stmt->fetch()) {
- ?>
- <form action="action/falck_date.php?>" method="POST">
- <?php echo $row_2['name']." - ".$row_2['address']." - ".$row_2['postal']." ".$row_2['city']."<br>".$row_2['contact']." - ".$row_2['mobile']." Serial: ".$row_2['serial']; ?>
- <br>
- <input type="date" name="pl_date" value="<?php echo $row_2['pl_date']; ?>">
- <input type="hidden" name="id" value="<?php echo $row_2['id']; ?>">
- <input type="submit" value="Opdater dato">
- </form>
- <?php } } ?>
- </div>
- </div>
- </div>
- </body>
- </html>
Indlæg senest redigeret d. 22.01.2016 22:44 af Bruger #16819