mysql_fetch_array只运行一次,应该是六次

时间:2014-08-05 06:30:42

标签: php mysql

我可以在我的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);

1 个答案:

答案 0 :(得分:1)

我想这是因为你设置了

$response["products"] = array();

每个周期内。将其移出此内部while