Sam
Sam

Reputation: 7058

MySQL while loop won't stop

I've recently created a PHP/MySQL while loop which fetches an array based on my parameters. From what I know about doing this, it should end when there are no more rows to grab. Mine just keeps going until I stop the page loading.

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']);
}

Upvotes: 2

Views: 1103

Answers (1)

bumperbox
bumperbox

Reputation: 10214

try like this most likely the inline query is being rerun everytime you step through the while loop

$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']);
}

Upvotes: 8

Related Questions