Php mysql_fetch_数组只运行一次,应该是六个

Php mysql_fetch_数组只运行一次,应该是六个,php,mysql,Php,Mysql,我可以在我的日志猫中看到,$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_

我可以在我的日志猫中看到,$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);
$result=mysql\u query(“选择*FROM`posts`WHERE facebook\u id=$fbid ORDER BY id DESC”)或die(mysql\u error());
while($row1=mysql\u fetch\u数组($result))
{
$mytime=$row1['time'];
$mylat=$row1[‘纬度’];
$mylon=$row1[‘经度’];
$mypostid=$row1['id'];
//从products表中获取所有产品
$check=mysql\u query(“选择facebook\u id作为fid,id作为uid,
TIMESTAMPDIFF(秒,`time`,'$mytime')作为timediff
从`员额`
其中'facebook\u id`!=$fbid

有'timediff`我想这是因为你设置了

$response[“products”]=array();


在每个周期内。将其移出此内部
,而

只是一个建议:不要这样做。使用php连接表确实不是一个好主意-使用mysql连接或嵌套查询。@pkelly
mysql\u num\u行($check)的输出是什么
?它输出6,这是应该显示的正确行数。我很确定你是正确的。我刚刚尝试了这个方法,结果发生了巨大的变化。这很复杂,所以我要测试一些东西,但我认为这是正确的。谢谢!@pkelly确保你将数组声明移到外部,而循环除外和其他预期的