I have a while loop that fetches rows from the MySQL database.
But I want to check if there are rows at all, if the table is empty, then echo an error.
I have a dirty way of doing this:
while($row = $fetch->fetch( PDO::FETCH_ASSOC ) $random[] = $row['a_column'] ) {
if (count($random) == 0) {
echo ' It's empty... ';
} else {
echo $row['a_column'];
}
Problem is that I have many columns and I am sure this is an extremely dirty way of doing so..
Problem
I am using PDO and I am not really sure how would I check if there are any rows in the table..
Question
How would I find out that the table doesn't contains any rows, if it doesn't, echo error.. if it does, echo results of a_column?.
Thanks!