While 循环只检索一个结果 [英] While loop only retrieving one result
问题描述
更新:似乎仍然无法弄清楚.如果有人能伸出援手,将不胜感激^^.
UPDATE: Still can't seem to figure it out. If anyone can lend a hand, it would be appreciated ^^.
我遇到了一个问题,我不确定我的代码在哪里崩溃.我有一个关注"功能,您可以在其中关注不同的注册用户.您关注的用户的用户 ID 存储在一个数组 (follower_array) 中.它从数组中检索每个成员,但是对于每个跟随的成员而不是显示所有内容,它只显示来自每个成员的 1 个最新成员.
I am having a problem and I'm not sure where my code is breaking down. I have a 'follow' function where you can follow different registered users. Their userID's of who you followed are stored in an array (follower_array). It's retrieving each member from the array, but of each member that's followed instead of displaying all the content, it's only displaying the 1 latest one from each member.
$broadcastList= "";
if ( $follower_array != "" ) {
$followArray = explode(",", $follower_array);
$followCount = count($followArray);
$i = 0;
$broadcastList .= "<table>";
foreach( $followArray as $key => $value ) {
$i++;
$sqlName = mysql_query("
SELECT username, fullname
FROM members
WHERE id='$value'
LIMIT 1
") or die ("error!");
while ( $row = mysql_fetch_array($sqlName) ) {
$friendUserName = substr($row["username"],0,12);
}
$sqlBroadcast = mysql_query("
SELECT mem_id, bc, bc_date, device
FROM broadcast
WHERE mem_id='$value'
ORDER BY bc_date ASC
LIMIT 50
") or die ("error!");
while ( $bc_row = mysql_fetch_array($sqlBroadcast) ) {
$mem_id = $bc_row['mem_id'];
$bc = $bc_row['bc'];
$dev = $bc_row['device'];
$bc_date = $bc_row['bc_date'];
$broadcastList .= "<td><a href='member.php?id=' .$value. ''>
$friendUserName</a> • $when_bc • Via: $dev <b>$bc</b></td></tr>";
}
broadcastList .= "</table>";
}
}
因此,它正在完全检索成员,但不会超过他们的最新广播".任何见解将不胜感激..谢谢!
So, it's retrieving the members entirely, but not more than their single latest "broadcast." Any insight would be appreciated.. thank you!
推荐答案
情况如下:
while( $row = some_next_result_function() ){
$result = $row["thing"];
}
每次都会覆盖 $result
,所以你只会得到最后一个结果.
Is going to overwrite $result
every time, so you'll only end up with the last result.
您需要制作一个列表并附加到它.
You need to make a list and append to it instead.
这篇关于While 循环只检索一个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!