on my website's homepage/login page im after a newsfeed like facebooks.

If its your first time to the site you will view a random few post's from people,

But if your a member and have signed up it will just show your friends.

currently i have a function

function friends_streams ($uid)
$res = mysql_query("SELECT * FROM friends WHERE uid='$uid'");
while ($row = mysql_fetch_array($res))
$fids[] = $row['fid'];

if (is_array($fids))
array_push($fids, $uid);

foreach ($fids as $value)
$my_in  = mysql_query("SELECT * FROM accounts where id = '$value' ORDER BY id DESC");
$my_info = mysql_fetch_array($my_in);

// output the users comments here 

but the trouble is it orders the post not by the newest but by the friend's id going in order e.g

people | ID numbers
you | 1
friend 1 | 2
friend 2 | 3
friend 3 | 4

friend 3 writes a post - it will show at the top.
friend 2 then writes a post after f3 - still at the top.
friend 3 writes a new post and it shows up in the middle,

hope you understand whaat i mean because its very hard to explian whats happening


What you need to do is combine your queries into one.

$sql = "SELECT `accounts`.* 
    FROM `accounts`
    INNER JOIN `friends` ON (`friends`.`uid` = `accounts`.`id`)
    ORDER BY `created` DESC";

$result = mysql_query($sql);

if(0 < mysql_num_rows($result)) {
    while(($account = mysql_fetch_assoc($result))) {

        // Use the account information


Without seeing your table structure, it's difficult to know whether this is any help. Therefore in the query, I have assumed that the date field is called `created`, thus sorting it by newest accounts first.