MySQL while循环不会停止

时间:2011-05-08 10:48:22

标签: php mysql while-loop

我最近创建了一个PHP / MySQL while循环,它根据我的参数获取数组。根据我所知道的,当没有更多行可以抓取时,它应该结束。我一直坚持下去,直到我停止加载页面。

while($row = mysql_fetch_array(mysql_query("SELECT username,password,title,message FROM notifications WHERE dateset = '$date'"))){
    $test = new Boxcar($row['username'],$row['password']); 
    $test->send($row['title'],$row['message']);
}

1 个答案:

答案 0 :(得分:8)

试试这样 每次进入while循环时,很可能都会重新运行内联查询

$result = mysql_query("SELECT username,password,title,message FROM notifications WHERE dateset = '$date'");

while($row = mysql_fetch_array($result)) {
    $test = new Boxcar($row['username'],$row['password']); 
    $test->send($row['title'],$row['message']);
}