我一直在社交网络上工作,我有一个粉丝表,用户可以为自己喜欢的乐队或名人创建个人资料,还有另一个名为朋友的表,他们可以订阅这些粉丝。我希望请求显示在粉丝页面管理员的通知中除外。 在第一个sql查询之后,它返回具有多个值的fanpages但是如果我回显下一个$ sql查询,则表明它只选择一个结果来查询而不是全部查询。
所以基本上我需要查看所有通过登录用户创建的所有粉丝的节日表($ log_username),然后我需要获取这些粉丝并查询朋友表以查明是否有人请求订阅用户粉丝页面??
这行代码$ fanpage_requests =“$ fansubSql”;输出SELECT * FROM friends WHERE user2 ='fan4'AND accepted ='0'ORDER BY datemade ASC作为唯一的结果,但应该有2个结果,因为fan3和fan4都有请求。
感谢你的帮助迈克尔
$fanpage_requests = '';
$fansql = "SELECT created_by, fanpage_name FROM `fanpages` WHERE created_by = '$log_username' ";
$fanquery = mysqli_query($db_conx, $fansql);
$fannumrows = mysqli_num_rows($fanquery);
if($fannumrows < 1){
$fanpage_requests = 'No friend requests';
} else {
while($row = mysqli_fetch_array($fanquery, MYSQLI_ASSOC)) {
$fanpage_name = $row["fanpage_name"];
$created_by = $row["created_by"];
$fansubSql = "SELECT * FROM friends WHERE user2='$fanpage_name' AND accepted='0' ORDER BY datemade ASC";
$fansubQuery = mysqli_query($db_conx, $fansubSql);
$fansubNumrows = mysqli_fetch_row($fansubQuery);
$fanpage_requests = "$fansubSql";
if($fansubNumrows < 1){
$fanpage_requests = "blah blah";
}
while ($fansubRow = mysqli_fetch_array($fansubQuery, MYSQLI_ASSOC)) {
$fansubreqID = $fansubRow["id"];
$fansubuser1 = $fansubRow["user1"];
$fansubdatemade = $fansubRow["datemade"];
$fansubdatemade = strftime("%B %d", strtotime($datemade));
$fansubthumbquery = mysqli_query($db_conx, "SELECT avatar FROM users WHERE username='$user1' LIMIT 1");
$fansubthumbrow = mysqli_fetch_row($thumbquery);
$fansubuser1avatar = $thumbrow[0];
$fansubuser1pic = '<img src="user/'.$user1.'/'.$user1avatar.'" alt="'.$user1.'" class="user_pic">';
if($fansubuser1avatar == NULL){
$fansubuser1pic = '<img src="images/avatardefault.jpg" alt="'.$user1.'" class="user_pic">';
}
$fanpage_requests .= '<div id="friendreq_'.$fansubreqID.'" class="friendrequests">';
$fanpage_requests .= '<a href="user.php?u='.$fansubuser1.'">'.$fansubuser1pic.'</a>';
$fanpage_requests .= '<div class="user_info" id="user_info_'.$fansubreqID.'">'.$fansubdatemade.' <a href="user.php?u='.$fansubuser1.'">'.$fansubuser1.'</a> requests friendship<br /><br />';
$fanpage_requests .= '<button onclick="fanReqHandler(\'accept\',\''.$fansubreqID.'\',\''.$fansubuser1.'\',\'user_info_'.$fansubreqID.'\')">accept</button> or ';
$fanpage_requests .= '<button onclick="fanReqHandler(\'reject\',\''.$fansubreqID.'\',\''.$fansubuser1.'\',\'user_info_'.$fansubreqID.'\')">reject</button>';
$fanpage_requests .= '</div>';
$fanpage_requests .= '</div>';
}
}
}
&GT;
答案 0 :(得分:0)
阅读文档。 mysqli_fetch_row不会返回数字。它从查询中返回一条记录。查看文档中的示例:您需要在循环内使用mysqli_fetch_row
来检索所有记录。
要知道查询返回的行数,请使用mysqli_num_rows。