2
I have the following select:
public function SelectLastError(){
try {
$stmt = $this->conn->prepare("SELECT Name, Data FROM Errors ORDER BY ErrorsId DESC LIMIT 3");
$stmt->execute();
while ($row = $stmt->fetch( PDO::FETCH_ASSOC )){
$rows[] = $row;
}
}catch (PDOException $exception){
echo $exception->getMessage();
echo "Error!";
return null;
}
}
And I’m trying to call it in an HTML like this:
<?php
$rows = $selectors->SelectLastError();
foreach ($rows as $row):?>
<a href="" class="list-group-item">
<i class="fa fa-bug"></i><?php echo $row['Name'];?>
<span class="pull-right text-muted small"><em><?php echo $row['Data']?></em>
</span>
</a>
<?php endforeach; ?>
Only he gives the title mistake : "Warning: Invalid argument supplied for foreach() in"
I’ve made the same idea in another foreach, I do not know why is appearing this error, SELECT this right already tested. Does anyone have any idea?
Ironically this means that there is no error o.o. I believe the way is to check if there is any value in
$rows
– rray
@rray Worst that has an error in hehehe function, I found missing a
return $rows;
in the end– Wagner Viana