Jump to content

there is one issue with my wall script


raovinesh90

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)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.