Jump to content

PHP / MYSQL Combine 2 SELECT query's


youvegotwood

Recommended Posts

Hello, I am trying to combine these two query's. Each one works separately but I need to perform a query that includes BOTH.

 

$query1 = "SELECT * FROM Listings WHERE lattitude BETWEEN $latminus AND $latplus";

$query2 = "SELECT * FROM Listings WHERE longitude BETWEEN $lonminus AND $lonplus";

 

The current PHP looks like the following (which works, however I need to add the additional query)

 

<?

$query = "SELECT * FROM Listings WHERE lattitude BETWEEN $latminus AND $latplus";

$results = mysql_query($query);

while($row = mysql_fetch_object($results))

{

      echo '

 

            var point = new GLatLng( '.$row->lattitude.','.$row->longitude.');

          var marker = createMarker(point, <b>Some stuff to display in the Info Window</b>);

            map.addOverlay(marker);';

}

?>

 

Thanks in advance for your help!

Link to comment
https://forums.phpfreaks.com/topic/117589-php-mysql-combine-2-select-querys/
Share on other sites

Hmmm when I change the query to this I get a Warning:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/content/.../....php on line 179

 

line 179 being the afore mentioned...

 

while($row = mysql_fetch_object($results))

it might be because the syntax of the statement is off:

 

$query2 = "SELECT * FROM Listings WHERE longitude BETWEEN $lonminus AND $lonplus AND latitude BETWEEN $latminus AND $latplus";

 

give that a whirl.  for future reference, invalid result resource usually implies that the query couldn't run due to syntax errors.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.