PHP code works when not put in a function
<p>I am trying to fetch data and encode it to JSON. I have this very confusing trouble. The code I have put in getAnnotions() function, when I do not put it in function, the while loop (commented as //This loop) is reached. Whereas when I encapsulate the same code in getAnnotions() function, that while loop is not reached. What might be the problem?</p>

<p>Here is the code:</p>

<pre><code>    &lt;?php

$city=$_GET["city"];
//$limit="1";
//$place=$_GET["place"];

getAnnotions("1");

function getAnnotions($limit)
{

    $con = mysql_connect("localhost","hidden","*******");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }

    mysql_select_db("merrycod_tummy", $con);

    $result = mysql_query("SELECT * FROM deal where city_names LIKE '%".$city."%'");

    $rows = array();

    while($row = mysql_fetch_array($result))
      {

          $rows[] = $row;


          $result2 = mysql_query("SELECT locationLat,locationLong FROM place where city ='".$city."' AND name='".$row['place_name']."' LIMIT ".$limit);



          while($row2 = mysql_fetch_array($result2))
          {
                $rows[] = $row2;

              //This loop

          }


      }

      echo json_encode($rows);


    mysql_close($con);

}
 ?&gt;
</code></pre>
