Explanation & Problem
Okay we have the following columns in our table,
[username] - [message] - [status] - [id]
In some specify PHP page, we use a while loop to post ALL of the rows that are stored in the database.
Okay, but now I want to check if there are any rows in the that table, if not, echo an error.
It's okay, simple as this:
$check = $fetch->rowCount();
and then
if ($check == 0) { }
But now, I want to check if column 'Status' is 0.
So if there are no rows with columns 'status' with value 0, it will echo a message. If there are no rows at all, it will echo a message.
If there are rows with column 'status' with value 0, it will echo all rows.
But there are some problems atleast for me, doing so.
Problem
I can't do all of the IF statements checks inside a loop, because a loop can't run if there are no rows.
But okay, we can do the check if there are rows outside of the loop, but how would I check if there are rows + they are not with status column holding value higher than '0'?
I got it to work somehow, but not like I wanted..
If there are rows with column 'status' with value 0 + rows with column status with value higher than 0 at same time, it will echo the message + show the rows, which shouldn't work like this!
This is the code I've tried to build:
$check = $fetch->rowCount();
if ($check == 0) {
echo '<br /> EMPTY';
}
while($row = $fetch->fetch( PDO::FETCH_ASSOC )) {
if ($check > 0 && $row['status'] == 0) {
echo
'<div class="background">'.$row['email'].' <span style="margin-left: 10px;"><font color="#ff0000">UNANSWERED</font></span><span id="right"><a href="index.php?recover='.$row['recover_id'].'">Read More</a></span></div><br />
';
} else {
echo 'There are no rows!';
}
}
Thank you for your help!