MySQLi查询仅返回一行 [英] MySQLi query returns only one row
问题描述
此代码仅返回一行,但应返回2行.我在phpMyAdmin中尝试了SQL,它完美地返回了2行.我在这里做错什么了?
This code only returns one row, but it should return 2 rows. I have tried the SQL in phpMyAdmin and it perfectly returned 2 rows. What am I doing wrong here?
$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_row = $request_list_result->fetch_array();
echo $request_list['user_fullname'];
顺便说一句,上面的代码通过以下脚本将程序移至profile.php:
By the way, the code above is getting process to profile.php via following script:
$index = new Template('views/template/one.php', array(
'subtitle' => 'Dashboard',
'stylesheets' => array('/assets/css/profile.css'),
'scripts' => array('/assets/js/dashboard.js'),
'sidebar' => 'sidebar.php',
'content' => 'views/profile.php',
'errors' => $errors,
'successes' => $successes,
'request_list' => $request_list_row //right here
), true);
推荐答案
您需要遍历结果(如TheSmose所述)
You need to loop through the results (as TheSmose mentioned)
while ($request_list_row = $request_list_result->fetch_array()) {
echo $request_list['user_fullname'];
}
AND ,您需要将结果数组$request_list
发送到模板而不是$request_list_row
.
AND you need to send the resulting array $request_list
to the template rather than $request_list_row
.
更改此
'request_list' => $request_list_row //right here
对此
'request_list' => $request_list //right here
如果在模板中不仅需要user_fullname
(并且mysqli_result::fetch_all
不需要PHP> = 5.3),那么您将需要在循环内构建自己的数组.
If you want more than just user_fullname
in your template (and you don't have PHP >= 5.3 required for mysqli_result::fetch_all
), then you will need to build up your own array inside the loop.
我不知道您的模板代码会有什么期望,但是您可以尝试
I don't know what your template code expects, but you could try
while ($request_list_row = $request_list_result->fetch_array()) {
echo $request_list[] = $request_list_row;
}
这篇关于MySQLi查询仅返回一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!