I have been working on a social network, i have a fanpages table that a user can create a profile for their favorite band or celebrity and another table called friends where they can subscribe to the fanpages. i then want the requests to appear in notifications for the fanpage admin to except. after the first sql query it returns fanpages with multiple values but if i echo the next $sql query it shows that its only selecting one result to query instead of all of them.
so basically i need to query fanpages table for all fanpages created_by the user logged on ($log_username), then i need to take those fanpages and query the friends table to find out if anyone has requested to subscribe to the users fan pages??
this line of code $fanpage_requests = "$fansubSql"; outputs SELECT * FROM friends WHERE user2='fan4' AND accepted='0' ORDER BY datemade ASC as the only result but there should be 2 results as both fan3 and fan4 have requests.
thanks for your help Michael
$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>';
}
}
}
?>