Hallo,

Ik heb volgens script gevonden op deze site, en ik heb het bijgewerkt voor te kunnen automatiseren.

index.php

<?php
include('../sec/inc_mysql_connect.php');
$sql = "SELECT VVBnummer, Adres, Postcode FROM tblscheidsrechters";// echo($sql);
$result = mysql_query($sql);

$sql_sh = "SELECT ID, SporthalAdres, Postcode FROM tblsporthal"; //echo('<br>' . $sql_sh);
$result_sh = mysql_query($sql_sh);
while($record = mysql_fetch_array($result))
{
while($record_sh = mysql_fetch_array($result_sh))
{
$fromAddress = $record['Adres'] . ',' . $record['Postcode']; echo($fromAddress . '<br>');
$toaddress = $record_sh['SporthalAdres'] . ',' . $record_sh['Postcode']; echo($toaddress . '<br>');
include('afstand.html');
}
}
?>

en dan uiteraard afstand.html:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=AIzaSyA_F6jvnChhojxeCahfRF1okNB9LOl11oU" type="text/javascript"></script> 
<script type="text/javascript">
function initialize() 
{ 
if (GBrowserIsCompatible()) 
{ 
// nieuw object ZONDER parameters, want we willen nl. geen geschreven route EN geen map tonen.... 
// http://code.google.com/apis/maps/doc...ml#GDirections 
gdir = new GDirections(); 
GEvent.addListener(gdir,"load", set_distance); 
} 
} 

function setDirections(fromAddress, toAddress, locale) 
{ 
// http://code.google.com/apis/maps/doc...ectionsOptions 
gdir.load("from: " + fromAddress + " to: " + toAddress, {locale: locale, travelMode:G_TRAVEL_MODE_DRIVING,avoidHighways: false} ); 
} 

function set_distance() 
{ 
// extra: foutafhandeling, kan handig zijn!!! 
handleErrors(); 
// document.getElementById("afstand").innerHTML = (gdir.getDistance().meters); 

var adl_afstand = (gdir.getDistance().meters)/500 
adl_afstand = Math.round(adl_afstand * 1,35) 



aant_km = 'Het aantal km is: ' + adl_afstand + ' km'

document.getElementById("ritprijs").innerHTML = aant_km; 
} 

</script>
</head> 
<body onload="initialize()" onunload="GUnload()"> 
<script language="javascript">setDirections(<?php echo($fromAddress) ?>, <?php echo($toaddress) ?>, 'BE'); </script>
</body>

Ik krijg enkel de adressen te zien ( echo's), geen afstanden van het javascript.
Kan er iemand mij helpen?
<?php echo ($gd->getDistance())/1000 ?>

zal wel moeten worden:

<?php echo $gd->getDistance()/1000; ?>

Aangepast, kan er iemand mij nog verder helpen met de code of een voorbeeld van de code voor een INSERT uit te voeren in de db?

Bedankt, en al zeker bedankt voor de hulp ik leer hier enorm veel :)
wat heb je al in de database aan tabellen en kolommen?

INSERT INTO klvv_sr_afstand_sh ( vvb_nr_sr, shid, afstand, tijd) VALUES('$vvb', '$shid', '$afstand', '$tijd');


Ik heb de SQL code zelf getest, deze is ok ( rechtstreeks in de mysql workbench )
<?php

$link = @mysqli_connect('localhost', 'user', 'password', 'database');

if (!$link) {
die('Connect Error: ' . mysqli_connect_errno());
}

$query = "INSERT INTO klvv_sr_afstand_sh ( vvb_nr_sr, shid, afstand, tijd) VALUES('".$vvb."', '".$shid."', '".$afstand."', '".$tijd."')";

if(mysqli_query($link, $query))
echo 'success!';
else
echo 'Error: ' . mysqli_error($link);

?>

Reageren