79560773

Date: 2025-04-07 21:04:47
Score: 0.5
Natty:
Report link

Why This Happens:

$res is a mysqli_result object, not an array.

You can’t use foreach directly on a mysqli_result object. That’s why $row ends up being null.

How to Fix It:

He needs to convert the result into something iterable, like an array. Option 1: Use while and fetch_assoc() (most common way)

<?php
while ($row = $res->fetch_assoc()) {?>
<div class="card Align-Content-On-X-Axis_center">
    <img src="./Images/images.jpeg" alt="ERR" />
    <h3><?= $row["Name"]; ?></h3>
</div>
<?php}?>

Option 2: Convert $res to an array first, then use foreach

<?php
$rows = [];
while ($row = $res->fetch_assoc()) {
    $rows[] = $row;
}
?>

<?php foreach ($rows as $row) { ?>
    <div class="card Align-Content-On-X-Axis_center">
        <img src="./Images/images.jpeg" alt="ERR" />
        <h3><?= $row["Name"]; ?></h3>
    </div>
<?php } ?>
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): Why This
  • Low reputation (1):
Posted by: Fares Mohamed