While and if statement in php with mysql -
i have been stuck problem awhile now. i'm sure answer on find able on google have been unable find words search last resort here. in advanced!
i have php code:
if(mysqli_num_rows($query) > 0) { while($row = mysqli_fetch_array($query)) { if ($row['status'] == "opened") { $test = "1"; } else { $test = "0"; } } } echo $test;
the problem occurs when there multiple entries in database , 1 of entries not have status = "opened" therefore $test returns "0". trying accomplish if of entries have status = "opened", $test return "1".
once again in advance help!
it might better directly select data need database instead of filtering out php.
select id, message, etc tickets status = 'opened' // if fetches data, have open tickets , have directly access data of open tickets. select count(*) total tickets status = 'opened' // result of number of total amount of opened tickets, perhaps better specific use.
but on subject on how fix loop can following:
$open = false; while($row = mysqli_fetch_array($query)) { if ($row['status'] == "opened") { $open = true; break; } }
as quit while loop, setting $open
futher use:
if($open){ // stuff; }
Comments
Post a Comment