Social networking status feed with php
<p>Please I need a help: am working on a social networking website using PHP. But I have a challenge when working on users status post update. If a user login, all of his/her post comes first then followed by his/her friends irrespective of whether his/her friends post are the latest post.
I got the list of his/her friends id from the database, explode it by , and then pass it through a foreach and then use the variable to fetch the post from the post table.
Please I need your help. I want it to be working like facebook status updates. Thanks</p>

<p>This is the code I used:</p>

<pre><code>`  

    &lt;?php
        if ($id == $_SESSION['username']){
        // Check it the current user and the id owner are friends so as determine whether to   display the interaction box or not
        $g = mysql_query("SELECT friends_username FROM myMembers WHERE username = '$nameuser'");
        if($g){
            $count = mysql_num_rows($g);
        }
        if($count){
            while($gn = mysql_fetch_assoc($g)){
                $frU = $gn['friends_username'];

            $efu = explode(",", $frU);
            //$fid2 = ksort($efu);
            foreach($efu as $fid){
                //$fid2 = asort($fid);
            //End of the foreach function
            //Use the $fid from the foreach function to get the name, id and username of the friends so as to use it for the post
    $g2 = mysql_query("SELECT * FROM myMembers WHERE username = '$fid'");
    if($g2){
        $count = mysql_num_rows($g2);
    }
    if($count){
        while($gn2 = mysql_fetch_array($g2)){
            $dfU = $gn2['username'];
            $dfi = $gn2['id'];
            $dfN = $gn2['firstname'].' '.$gn2['lastname'];
            }
        }//End of the foreach function
            //$ifu = in_array($id, $efu);
            //$ndfU = sort($dfU);
            //$dfU2 = sort($dfU);
            $sql_post = mysql_query("SELECT id, mem_id, post, post_date,     pix_name, pix_ex FROM status_post WHERE username = '$dfU' ORDER BY post_date DESC LIMIT     100")or die (mysql_error());
    while($row = mysql_fetch_array($sql_post)){

    $blabid = $row["id"];
    $uid = $row["mem_id"];
    $post = $row["post"];
    $post_date = $row["post_date"];
    $post_date = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($post_date));
    $pix = $row["pix_name"];
    $pex = $row["pix_ex"];

    if($pix != ""){
        $post = "&lt;img src=\"Photos/$dfU/$pix\" width=\"120px\" alt=\"$pix added by $dfN\" title=\"photo added by $dfN\"/&gt;";
    }

        $check_pic =  "profilephoto/$dfU.jpg";

        if (file_exists($check_pic)) {
    $user_pic2 = "&lt;img src=\"$check_pic\" width=\"60px\" /&gt;"; // forces picture to be 100px wide and no more
    } else {
    $user_pic2 = "&lt;img src=\"$default_pic\" width=\"60px\" /&gt;"; // forces default picture to be 100px wide and no more
    }
                $postDisplayList .= '

                &lt;table  bgcolor="#D9ECFF" cellpadding="5" width="100%"&gt;
                    &lt;tr bgcolor="#FFF"&gt;
                    &lt;td width="10%" valign="top" bgcolor="#FFF"&gt;' . $user_pic2 . '&lt;/td&gt;
                    &lt;td width="90%" valign="top" style="line-height:1.5em;"&gt;&lt;span style="font-size:10px; font-weight:bold; color:#A6A6A6; font-style:italic;"&gt;&lt;a href="profile.php?id=' . $uid . '" style="text-decoration:none; color:#043; font-size:11px; font-style:normal; margin-right:30px;"&gt;' . $dfN . '&lt;/a&gt; ' . $post_date . ' &lt;/span&gt;&lt;br /&gt;
            ' . $post . '&lt;/td&gt;
            &lt;/tr&gt;&lt;/table&gt;';       

}
}
    }       }

}//End of if session = $id

    //If the viewer is not the owner of the page
    else if($id == $_GET['id']){

    $g3 = mysql_query("SELECT * FROM myMembers WHERE id = '$id'");
    if($g3){
        $count = mysql_num_rows($g3);
    }
    if($count){
        while($gn3 = mysql_fetch_array($g3)){
            $dfU = $gn3['username'];
            $dfi = $gn3['id'];
            $dfN = $gn3['firstname'].' '.$gn3['lastname'];
            }

    $sql_post = mysql_query("SELECT id, mem_id, post, post_date, pix_name, pix_ex FROM status_post WHERE username = '$dfU' ORDER BY post_date DESC LIMIT 100")or die (mysql_error());
    while($row = mysql_fetch_array($sql_post)){

    $blabid = $row["id"];
    $uid = $row["mem_id"];
    $post = $row["post"];
    $post_date = $row["post_date"];
    $post_date = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($post_date));
    $pix = $row["pix_name"];
    $pex = $row["pix_ex"];

    if($pix != ""){
        $post = "&lt;img src=\"Photos/$dfU/$pix\" width=\"120px\" alt=\"$pix added by $dfN\" title=\"photo added by $dfN\"/&gt;";
    }

        $check_pic =  "profilephoto/$dfU.jpg";

        if (file_exists($check_pic)) {
    $user_pic2 = "&lt;img src=\"$check_pic\" width=\"60px\" /&gt;"; // forces picture to be 100px wide and no more
    } else {
    $user_pic2 = "&lt;img src=\"$default_pic\" width=\"60px\" /&gt;"; // forces default picture to be 100px wide and no more
    }
                $postDisplayList .= '

                &lt;table  bgcolor="#D9ECFF" cellpadding="5" width="100%"&gt;
                    &lt;tr bgcolor="#FFF"&gt;
                    &lt;td width="10%" valign="top" bgcolor="#FFF"&gt;' . $user_pic2 . '&lt;/td&gt;
                    &lt;td width="90%" valign="top" style="line-height:1.5em;"&gt;&lt;span style="font-size:10px; font-weight:bold; color:#A6A6A6; font-style:italic;"&gt;&lt;a href="profile.php?id=' . $uid . '" style="text-decoration:none; color:#043; font-size:11px; font-style:normal; margin-right:30px;"&gt;' . $dfN . '&lt;/a&gt; ' . $post_date . ' &lt;/span&gt;&lt;br /&gt;
            ' . $post . '&lt;/td&gt;
            &lt;/tr&gt;&lt;/table&gt;';       
    }
    }
    }//End of if $_GET['id'] = $id

    ?&gt;`
</code></pre>
