php - Can only see friends lists if logged in with user id of 1 -
i'm implementing friends list system on site, , i've gotten display friends names have accepted(therefore accepted has value of 1), , when visit dummy accounts can see friends, when logged in dummy account can see either, manually changed user_id in database "1" , logged out , in , discovered it's working user_id of 1, here code. it's not mysqli yet, that's next step.
<h1>friends</h1> <?php $user_id = user_id_from_username($username); if($_session['user_id'] == $user_id){ $logged_user_id = $_session['user_id']; $result = mysql_query("select * `friends` `friend_id`='{$logged_user_id}' , `user_id`!='{$logged_user_id}' , `accepted`='1'"); while ($row = mysql_fetch_array($result)){ $friend_id = $row['user_id']; /*get friend details*/ $fetch_details = mysql_fetch_object(mysql_query("select * `users` `user_id`='{$friend_id}'")); echo $fetch_details->username; echo '<br/>'; } } else if($_session['user_id'] != $user_id){ $user_id = user_id_from_username($username); $logged_user_id = $user_id; $result = mysql_query("select * `friends` `user_id`='{$logged_user_id}' , `friend_id`!='{$logged_user_id}' , `accepted`='1'"); while ($row = mysql_fetch_array($result)){ $friend_id = $row['friend_id']; /*get friend details*/ $fetch_details = mysql_fetch_object(mysql_query("select * `users` `user_id`='{$friend_id}'")); echo $fetch_details->username; echo '<br/>'; } } ?>
tables
friends id(ai) user_id friends_id datemade accepted(enum 0, 1) users user_id(ai) username profile active
in first sql query use same variable twice filter:
`friend_id`='{$logged_user_id}' , `user_id`!='{$logged_user_id}'
this not give expected results.
you add print_r($row)
check if expected results database make sure queries want them to.
Comments
Post a Comment