raovinesh90 Posted July 30, 2013 Share Posted July 30, 2013 hi guys, i have a wall script. it is working fine but i'm facing one issue that is, 'single post is shown multiple times on user's own wall and one time on his friend wall. for example if A have 5 friends script will show single post 5 times. As it is showing one time on friend wall, this portion is working good but issue is on users own wall.here is code:$qfu = "SELECT * FROM my_friends WHERE (user_id = '$user_id' OR friend_id = '$user_id') AND status = '1'";$fu = mysql_query($qfu) or die(mysql_error());$rowfu = mysql_num_rows($fu);while($rowf = mysql_fetch_array($fu)){$user_id = $rowf['user_id'];$friend_id = $rowf['friend_id']; $querymsgs = "SELECT * FROM messages where uid_fk = '$friend_id' OR uid_fk = '$user_id' order by msg_id DESC Limit 1"; $qmsgs = mysql_query($querymsgs) or die(mysql_error());$row_msgs = mysql_num_rows($qmsgs);while($msgs = mysql_fetch_array($qmsgs)){$msg_id = $msgs['msg_id'];$orimessage = $msgs['message'];$message = tolink(htmlentities($msgs['message']));$time = $msgs['created'];$privacy = $msgs['privacy'];if($privacy=='0'){ $privacy='Only Me';} elseif($privacy=='2'){ $privacy='Public';} else { $privacy='Friends';}$uid=$msgs['uid_fk'];$fullname=$msgs['fname']." ".$msgs['lname'];$face=$Wall->Avatar($uid);$commentsarray=$Wall->Comments($msg_id);?>please help me to get rid off this issue. I'm trying since 2 weeks to solve it but failed to get any good result. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted July 31, 2013 Share Posted July 31, 2013 you are runbning a query within a loop - don't do that. Learn how to join tables and your problems (this one at least) will go away. Quote Link to comment Share on other sites More sharing options...
yperevoznikov Posted August 2, 2013 Share Posted August 2, 2013 As Muddy_Funster said try JOIN of SQL and one loop, something like that: SELECT DISTINCT tm.* FROM my_friends tf JOIN messages tm ON tm.uid_fk = tf.user_id OR tm.uid_fk = tf.friend_id WHERE (tf.user_id = '$user_id' OR tf.friend_id = '$user_id') AND tf.status = '1' ORDER BY msg_id DESC LIMIT 10 this SQL query will return all messages that are related to current user and all his friends (first 10 of course) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.