Troubleshooting MySQLi Query Returning Only One Row
This issue arises when a MySQLi query fetches only a single row instead of multiple rows as expected. It occurs when the user retrieves data using mysqli_result::fetch_array, which fetches only one row at a time.
To resolve this, the code should employ mysqli_result::fetch_all instead. This method retrieves all rows from the result set, addressing the issue of returning a limited number of rows.
Here is the corrected code:
$request_list_result = $mysqli->query("SELECT buddy_requester_id, buddy_reciepient_id, user_id, user_fullname FROM sb_buddies JOIN sb_users ON buddy_requester_id=user_id WHERE buddy_status='0' AND buddy_reciepient_id='". get_uid() ."'); $request_list = $request_list_result->fetch_all(); foreach ($request_list as $request_list_row) { echo $request_list_row['user_fullname']; }
This modification ensures that all rows returned by the MySQLi query are retrieved and displayed.
The above is the detailed content of Why is My MySQLi Query Returning Only One Row?. For more information, please follow other related articles on the PHP Chinese website!