MySQLi Query Only Returns One Row
In the provided code, the author attempts to fetch multiple rows from the database using MySQLi, but the query only returns a single row. This is despite confirming that the SQL query returns two rows when executed directly in phpMyAdmin.
The Issue
The issue lies in the method used to fetch data from the MySQLi result object. In the code, fetch_array() is used, which retrieves only the first row of the result set. To retrieve all rows, fetch_all() should be used instead.
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(); // Now $request_list holds all rows in the result set
Additional Resources
For more information on fetching data from MySQLi result sets, refer to the following resource:
The above is the detailed content of Why Does My MySQLi Query Only Return One Row?. For more information, please follow other related articles on the PHP Chinese website!