Foreach Issue

Hello,

I am attempting to display every row (3) from my table and to stop when the row has nothing in it.

My code:

<?php

@$link = new mysqli("localhost", "user", "pass", "db");

if ($link->connect_errno) {

die ("Error: {$link->connection_error}");

}

$result = $link->query("SELECT * FROM likes");
$num_rows = $result->num_rows;

while ($get_info = $num_rows->fetch_object()) {

foreach ($get_info as $post) {

if (!empty($post)) {

echo "{$post}<br><br>\
\
";

}

}

}

@$link->close();

?>

However, it results in error.
Any ideas?

Thanks.
Eric

Can you please specify the error in detail, to point the problem quickly.

Of course. The error is as follows: “Fatal error: Call to a member function fetch_object() on a non-object in /home2/cfpmedi1/public_html/test.php on line 18”.

while ($get_info = $num_rows->fetch_object()) {

surely you meant $result->fetch_object here…

Well, that corrects that… However, I am still not obtaining the desired result.

Without knowing the structure of your table, and the record(s) inside of it, I cant really answer the question… however you probably want to use fetch_assoc instead of fetch_object.