我可以在 logcat 中看到 $check 查询只运行一次,而它应该为 $result 查询的每个结果运行一次,即6. 我已经花了好几个小时来解决这个问题,但我就是不明白为什么它不能正常工作。
$check 只运行一次是否有明显的原因?
$result = mysql_query("SELECT * FROM `posts` WHERE facebook_id = $fbid ORDER BY id DESC") or die(mysql_error());
while ($row1 = mysql_fetch_array($result))
{
$mytime = $row1['time'];
$mylat = $row1['latitude'];
$mylon = $row1['longitude'];
$mypostid = $row1['id'];
// get all products from products table
$check = mysql_query("SELECT facebook_id as fid, id as uid,
TIMESTAMPDIFF(SECOND, `time`, '$mytime') AS timediff
FROM `posts`
WHERE `facebook_id` != $fbid
HAVING `timediff` <= '180'
ORDER BY `time` DESC") or die(mysql_error());
if (mysql_num_rows($check) > 0)
{
$response["products"] = array();
while ($row = mysql_fetch_array($check))
{
// temp user array
$product = array();
$product["facebookid"] = $row["fid"];
$product["timediff"] = $row["timediff"];
$product["theirpostid"] = $row["uid"];
$product["mypostid"] = $mypostid;
// push single product into final response array
array_push($response["products"], $product);
}
}
}
$response["success"] = 1;
echo json_encode($response);
最佳答案
我想这是因为你设置了
$response["products"] = array();
在每个周期内。将其移出这个内部 while
。
关于php - mysql_fetch_array 只运行一次,应该是 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25132452/