I'm working on a project, where the logged in user should be able to post notes on the homepage, and being logged in the certain user's notes should be printed above the new note form.
I've written a function for that, where the mysqli_query
recognizes all the 6 entries I have, but the mysqli_fetch_assoc
prints only the first note out of 6. What could I do wrong? Here is my code:
<?php
function find_notes_by_id($user_id) {
global $connection;
$safe_user_id = mysqli_real_escape_string($connection, $user_id);
$query = 'SELECT content ';
$query .= 'FROM notes ';
$query .= 'WHERE user_id = '.$safe_user_id;
$result = mysqli_query($connection, $query);
//mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 6 [type] => 0 )
confirm_query($result);
$row = mysqli_fetch_assoc($result);
//Array ( [content] => First! ) = it only shows the very first element
return $row;
}
?>
<?php
$notes_set = find_notes_by_id($userRow['id']);
foreach($notes_set as $note){
echo $note;
echo "<br />";
}
?>
</div>