Guys i`m trying to archive something like facebook,twitter wall Display.
I have a friend table,inside it has id,friendid and userid.
also got feeds table which contains id,action,sender_id,statusid,status,date.
What i have succeeded to do is if You are logged in you can see all the updates from your friends...As the code below Shows.
Now i want in the same sql script to be able to view the updates made by me(OWN UPDATES,like status,added a friend and so so) including friends.

$logged_id=$_SESSION['id'];//logged in User
include"config.php";//db connection
/****display feeds,wall*********/
$query="SELECT
 feeds.id
,feeds.action
,feeds.sender_id
,feeds.friend
,feeds.statusid
,feeds.status
,feeds.date
FROM friends 
INNER JOIN feeds
ON friends.friendid=feeds.sender_id
WHERE (friends.userid='$logged_id')ORDER BY id DESC LIMIT 30";
$result=mysql_query($query);
$countfeed=mysql_num_rows($result);
if($countfeed>0){
while($row=mysql_fetch_array($result))
 {
  $updateid=$row['id'];
  $senderupdate=$row['sender_id'];
  $friend=$row['friend'];
  $status=$row['status'];
  $statusid=$row['statusid'];
  //$action=$row['action'];
   //query the name of the update sender
    $changeid=mysql_fetch_array(mysql_query("SELECT names FROM profile WHERE  id='$senderupdate'"));
  $hisname=$roo['names'];
   

  if($statusid){  //check if wall status

    echo"$hisname updated his wall $status<br/>";

  }elseif($friend){
    //select the name of the friend
     echo"$hisname   added $friend as a friend<br/>";
  
  }




 }

}else{
echo"THERE ARE NO FRIENDS UPDATE<br/>";
echo"Add more friends to receive their updates";
}

I KNOW ITS SOMETHING TO DO WITH SQL,BUT I HAVE TRIED WITH NO SUCCESS.

I WILL BE GRATEFULL IF SOMEONE WILL HELP ME IN THIS PROBLEM.

...
FROM friends
RIGHT JOIN feeds
ON friends.friendid=feeds.sender_id OR feeds.sender_id = '$logged_id'
...

(I haven't tested this, not at my computer.)
If you right join to the feeds (a feed without a friend that still satisfies the join condition) and store your user events as feed entries this should do the trick.

Thankx @madCoder,for your reply.
I tested the code
1)Its taking very long time to load.
2)successfuly it is loading my friend updates but whenever it reaches my own updates it loads the same result untill the loop ends.
I HAVE ATTACHED A PICTURE TO ELABORATE WHAT IS HAPPENING.

Thank you man, 4 ur help.

people please help))) i havent got solution yet.

Please post schema and a little sample data. Might be best to post this into a clipboard paste site like http://yourpaste.net/new or something.

Use phpMyAdmin or mysql_dump to export the data. It is easier to test out queries when there is something to work with.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.