MySQL Forums
Forum List  »  PHP

mysql_fetch_assoc(): supplied argument is not a alid MySQL result resource
Posted by: a aoao
Date: March 22, 2007 06:52PM

i keep getting the same error no matter what sql query i use. they were all working when i had the file locally hosted on my machine, but since i've started hosting it on a web server it wont work! any ideas!!?

here's my code...

<?
function distance($lat1, $lon1, $lat2, $lon2, $unit) {


$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);

if ($unit == "K") {
return ($miles * 1.609344);
} else if ($unit == "N") {
return ($miles * 0.8684);
} else {
return $miles;
}

}
$host = 'localhost';
$user = '';
$pass = '';
$dbname = 'rory_racetrack';
echo "Hello world! <br>";
$db = mysql_connect($host, $user, $pass);

if(!$db) {
echo 'Could not connect to mysql';
exit;
if (!mysql_select_db($dbname, $db)) {
echo 'Could not select database';
exit;
}
}


$query = "SELECT * FROM RHUMB";
$query = mysql_query($query);
echo $query;
//echo "<waypoint>";
while ($row=mysql_fetch_assoc($query)){
//echo 'Rhumb Number= '.$row['rhumb'].' latitude= '.$row['latitude'].' longitude= '.$row['longitude'];
$check = $row['rhumb'];
echo "RHUMB:";
echo $check;
echo "<br>";
$latitude = $row['latitude'];
$longitude = $row['longitude'];
$check++;
echo "TWO :";
echo $check;
echo "<br>";
$check2 = $check;
echo "CHECK 2 ";
echo $check2;
echo "<br>";
//echo "<br>";
$query2 = "SELECT rhumb, latitude, longitude FROM RHUMB WHERE RHUMB = " . $check2 . ";";
$query2 = mysql_query($query2);
while ($row=mysql_fetch_assoc($query2)){
//echo 'Rhumb Number= '.$row['rhumb'].' latitude= '.$row['latitude'].' longitude= '.$row['longitude'];
$check2 = $row['rhumb'];
$latitude2 = $row['latitude'];
//echo $latitude2;
echo "<br>";
$longitude2 = $row['longitude'];
}
$disto = distance($latitude , $longitude , $latitude2 , $longitude2 , "n") . " nautical miles<br>";
echo $disto;
$overall = $overall + $disto;
}
echo "<br>";
echo $overall . "Nautical Miles";
/*
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "m") . " miles<br>";
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "k") . " kilometers<br>";
echo distance(32.9697, -96.80322, 29.46786, -98.53506, "n") . " nautical miles<br>";
*/
?>

Options: ReplyQuote


Subject
Written By
Posted
mysql_fetch_assoc(): supplied argument is not a alid MySQL result resource
March 22, 2007 06:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.