PDA

View Full Version : Ordering by last event problem with a twitter style feed



Nathan Joshua
14 Aug 2012, 07:15 AM
Hello all.

I need some help ordering a twitter style feed by latest event.

Here is my code so far:
Code:


$result = mysql_query("SELECT * FROM table_follows WHERE follows='$userloggedin'");
while($row = mysql_fetch_array($result))
{
$listoffollowers = mysql_real_escape_string($row['beingfollowed']);


$resulttwo = mysql_query("SELECT * FROM table_images WHERE username='$listoffollowers' ORDER BY date DESC");
while($rowtwo = mysql_fetch_array($resulttwo))
{

$imageuser = mysql_real_escape_string($rowtwo['username']);
$imagedate = mysql_real_escape_string($rowtwo['date']);


$echoevent = "$imageuser uploaded an image on $imagedate";

echo $echoevent;
}


}

This will echo the events of other users the $userloggedin is currently following in reverse alphabetical order.

For example:

Tom uploaded an image on 25th of June
Tom uploaded an image on 21st of June
Tom uploaded an image on 12th of June
Mary uploaded an image on 31st of June
Mary uploaded an image on 3rd of June
Adam uploaded an image on 13th of June
Adam uploaded an image on 12th of June


What I want is to order the event by date so it will echo this out:

Mary uploaded an image on 31st of June
Tom uploaded an image on 25th of June
Tom uploaded an image on 21st of June
Adam uploaded an image on 13th of June


I'm thinking this might be possible by converting the $imagedate to seconds and sorting by number in an array. However, I have no idea how to do this!

If anyone has an alternative solution to what I'm aiming for I would love to hear it.