Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/280654-there-is-one-issue-with-my-wall-script/
Share on other sites

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)

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.