Hello,
I have a problem with my php script.
Everything works fine except when i will write the data to the database.
I get a error Warning: Wrong parameter count for mysql_query()
Here is my code:
<?php
include('../sec/inc_mysql_connect.php');
include 'googledistance.class.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>');
$gd = new GoogleDistance($fromAddress, $toaddress);
$vvb = $record['VVBnummer'];
$shid = $record_sh['ID'];
$afstand = $gd->getDistance();
$tijd = $gd->getDuration();
?>
<body>
<p>Scheidsrechter: <?php echo($record['VVBnummer']); ?></p>
<p>Sporthal: <?php echo($record_sh['ID']); ?></p>
<p>Afstand in km (h/t): <?php echo $gd->getDistance()/1000 ; ?></p>
<p>Tijd in minuten: <?php echo $gd->getDuration()/60; ?></p>
<p>Gevonden oorsprong: <?php echo $gd->getOrigin(); ?></p>
<p>Gevonden bestemming: <?php echo $gd->getDestination(); ?></p>
<hr />
</body>
<?php
$sql = "INSERT INTO klvv_sr_afstand_sh ( vvb_nr_sr, shid, afstand, tijd) VALUES('$vvb', '$shid', '$afstand', '$tijd')"; echo($sql);
$record = mysql_query();
}
}
?>
the google class is:
<?php
class GoogleDistance
{
private $obj;
function __construct($origin, $destination)
{
$this->obj = $this->run($origin, $destination);
}
public function getObject()
{
return $this->obj;
}
public function getOrigin()
{
return $this->obj->origin_addresses[0];
}
public function getDestination()
{
return $this->obj->destination_addresses[0];
}
public function getDistance()
{
return $this->obj->rows[0]->elements[0]->distance->value;
}
public function getDuration()
{
return $this->obj->rows[0]->elements[0]->duration->value;
}
private function run($origin, $destination)
{
$path = 'http://maps.googleapis.com/maps/api/distancematrix/json?origins=' .
$this->formatstring($origin) . '&destinations=' .
$this->formatstring($destination) .'&language=nl_NL&sensor=false';
// our curl handle (initialize ifrequired)
static $ch = null;
if (is_null($ch)) {
$ch = curl_init();
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $path);
curl_setopt($ch, CURLOPT_HEADER, 0);
// run the query
$res = curl_exec($ch);
if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
$dec = json_decode($res);
if(!$dec)
{
echo '<pre>';
print_r($res);
echo '</pre>';
throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
}
return $dec;
}
private function formatstring($text)
{
return str_replace(' ', '+', $text);
}
};
Thx for the help