How do those values related to the information returned from the database? If they are just representative of the columns returned, row-by-row, then I would recommend you use PDO and the fetchAll() function, which will return what you need.
I couldn’t make the connection with the db here. I tried your suggestion, but I couldn’t make it work. Instead of given values in $rows = array( …) , I want it to grab the data from the db.
First, there is no need for the if()–if there are no results, the loops will have nothing to loop over anyways.
Second, you fetch each row as object and then loop over the object (or rather something totally unrelated, as $rows is not coming from the DB), WTF? It suffices to foreach() over $result as mysqli results are iterable.
And because of that, the variables inside your foreach() are not what you expect them to be.
That’s not the function I suggested, but I didn’t realise you were using mysqli rather than PDO. I’m not sure what the equivalent is in mysqli. Perhaps, if you’re using the native driver:
But if your driver doesn’t support it, I’d loop through using something like:
if ($result) {
$rows = array();
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
}
First things first - can you get the query to run without errors and return some results? Your display loop seems quite complex, so first make sure the data is correct before you try to figure out any issues with that.