<?php
if(!$dbconnect = mysql_connect('localhost', 'root', 'root')) {
echo "Connection failed to the host 'localhost'.";
exit;
} // if
if (!mysql_select_db('Hotels')) {
echo "Cannot connect to database 'Hotels'";
exit;
} // if
$lat1 = 53.65274;
$long1 = -2.63241;
$distance = 200;
$table_id = 'Hotel';
$dbresult = mysql_query('SELECT 3963.191 * ACOS( (SIN(PI()*".$lat1."/180)*SIN(PI()*Lat/180))
+(COS(PI()*".$lat1."/180)*cos(PI()*Lat/180)*COS(PI()*Long/180-PI()*".$long."/180))), CompanyName, Address FROM ".$table_id." WHERE <= 1.5 LIMIT 25');
$companyName ="null";
$address ="null";
while ($row = mysql_fetch_assoc($dbresult)) {
$companyName = $row['CompanyName'];
$address = $row['Address'];
echo $companyName;
echo $address;
}
?>
MySql Structure:
Code:
ID int(6) No None auto_increment
Category varchar(255) latin1_swedish_ci No None
Location text latin1_swedish_ci No None
CompanyName varchar(150) latin1_swedish_ci No None
Address varchar(255) latin1_swedish_ci No None
City varchar(50) latin1_swedish_ci No None
State varchar(50) latin1_swedish_ci No None
Country varchar(50) latin1_swedish_ci No None
PostalCode varchar(10) latin1_swedish_ci No None
Phone varchar(20) latin1_swedish_ci No None
Email varchar(50) latin1_swedish_ci No None Website varchar(100) latin1_swedish_ci No None
Lat double No None
Long double No None
Link text latin1_swedish_ci No None
I get the error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Users/dollyc1981/Desktop/Sites/gpsTest.php on line 26
Line 26 is: while ($row = mysql_fetch_assoc($dbresult)) {
What I am trying to achieve is from the long and lat of a mobile device such as iphone is sent to a php script that requests the data from mysql DB the query brings back the surrounding companies with in a given disstance.
I haven't got any idea really how the to achieve this I have tried look on some good resources but I can't get anything to work I would appreciate the help on this. This as had me for a few weeks now.
I have even tried run the mysql query direct on my phpMyadmin.
I have seen some posts on this site giving tutorials for this, but I don't know what Im doing wrong because I can't get it to work for me.
if(!$dbconnect = mysql_connect('localhost', 'root', 'root')) {
echo "Connection failed to the host 'localhost'.";
exit;
} // if
if (!mysql_select_db('Hotels')) {
echo "Cannot connect to database 'Hotels'";
exit;
} // if
$lat1 = 53.65274;
$long1 = -2.63241;
$distance = 200;
$table_id = 'Hotel';
$dbresult = mysql_query('SELECT 3963.191 * ACOS( (SIN(PI()*".$lat1."/180)*SIN(PI()*Lat/180))
+(COS(PI()*".$lat1."/180)*cos(PI()*Lat/180)*COS(PI()*Long/180-PI()*".$long."/180))), CompanyName, Address FROM ".$table_id." WHERE <= 1.5 LIMIT 25');
$companyName ="null";
$address ="null";
while ($row = mysql_fetch_assoc($dbresult)) {
$companyName = $row['CompanyName'];
$address = $row['Address'];
echo $companyName;
echo $address;
}
?>
MySql Structure:
Code:
ID int(6) No None auto_increment
Category varchar(255) latin1_swedish_ci No None
Location text latin1_swedish_ci No None
CompanyName varchar(150) latin1_swedish_ci No None
Address varchar(255) latin1_swedish_ci No None
City varchar(50) latin1_swedish_ci No None
State varchar(50) latin1_swedish_ci No None
Country varchar(50) latin1_swedish_ci No None
PostalCode varchar(10) latin1_swedish_ci No None
Phone varchar(20) latin1_swedish_ci No None
Email varchar(50) latin1_swedish_ci No None Website varchar(100) latin1_swedish_ci No None
Lat double No None
Long double No None
Link text latin1_swedish_ci No None
I get the error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Users/dollyc1981/Desktop/Sites/gpsTest.php on line 26
Line 26 is: while ($row = mysql_fetch_assoc($dbresult)) {
What I am trying to achieve is from the long and lat of a mobile device such as iphone is sent to a php script that requests the data from mysql DB the query brings back the surrounding companies with in a given disstance.
I haven't got any idea really how the to achieve this I have tried look on some good resources but I can't get anything to work I would appreciate the help on this. This as had me for a few weeks now.
I have even tried run the mysql query direct on my phpMyadmin.
I have seen some posts on this site giving tutorials for this, but I don't know what Im doing wrong because I can't get it to work for me.