1

Can anybody see why code 1 works but code 2 doesn't? its driving me crazy!!!

CODE 1:

<?PHP
$con=mysqli_connect("a","b","c","d");

$result = mysqli_query($con,"SELECT * FROM map_places");
 while($row = mysqli_fetch_array($result))
  {
  $lat2=$row['latitude'];
  $lon2=$row['longitude'];
  echo  'var myLatLng = new google.maps.LatLng('.$lat2.','.$lon2.');';
  echo  'var myMarker = new google.maps.Marker({';
  echo      'position: myLatLng,';
  echo      'map: map,';
  echo  '});';
  }
?>

CODE 2:

<?PHP
 $con=mysqli_connect("a","b","c","d");
 $min = (int)$_POST['min'];
 $sql = "
   SELECT map_places.latitude, map_places.longitude
   FROM map_places
   INNER JOIN map_items ON (map_items.host_id = map_places.id)
   WHERE map_items.value >".$min."
   GROUP BY map_places.id
     ";

$result1 = mysqli_query($con,$sql);
while($row1 = mysqli_fetch_array($result1));
  {
$lat1=$row1['latitude'];
$lon1=$row1['longitude'];

echo  'var myLatLng = new google.maps.LatLng('.$lat1.','.$lon1.');';
echo  'var pokerMarker = new google.maps.Marker({';
echo      'position: myLatLng,';
echo      'map: map,';
echo  '});';
  }
?>

They are essentially the same code with code 1 pulling all of the data and posting it onto a Google map and code 2 pulling certain data (all that have a value higher than $min) and putting it on a Google map, I have put the select through MySQL and it pulls the correct data, however if I use (int) on $row1... and $row2... the lat long values posted on my map are 0,0. Can anybody explain why this happens? (all code outside what I have posted is the same for code 1 and code 2 and as code 1 works my problem should lie somewhere here). Thank you for any help trying to get code 2 to work has been driving me crazy for days!!

1
  • May be you need to debug the code. first execute your query on the phpmyadmin and check is it returning some data. and then check what is the indexes in the $row1 by print_r($row1);. Oct 24, 2013 at 14:09

1 Answer 1

2
while($row1 = mysqli_fetch_array($result1));

remove the ; at the end of the line

1
  • Oh my days! Thank you I cant believe all the times I've read the code looking for my downfall and I completely overlooked that! lol lifesaver!! Oct 24, 2013 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.