我正在尝试获取数据并将其编码为 JSON。我有这个非常混乱的麻烦。我放在 getAnnotions() 函数中的代码,当我不把它放在函数中时,会到达 while 循环(注释为 //This loop)。而当我将相同的代码封装在 getAnnotions() 函数中时,不会到达该 while 循环。可能是什么问题?
这是代码:
<?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);
}
?>