ThisNameWillDo!
16-03-2010, 03:19 PM
Hey, I'm trying to code a system that shows what a user has done, for example, if a user has became friends with someone, or posted something on their profile. My coding is below:
<?
include "config.php";
if ($logged[username]) {
echo "<center><font class='normaltext'><u>Friend Updates</u><br /><br /></center><table border='0' cellspacing='2' cellpadding='0' class='normaltext'>";
$username = $logged['username'];
$getmates = mysql_query("SELECT * FROM friends WHERE to_user = '$username' AND confirmed = 'True'") or die(mysql_error());
$getmates2 = mysql_query("SELECT * FROM friends WHERE from_user = '$username' AND confirmed = 'True'") or die(mysql_error());
$number1 = mysql_num_rows($getmates);
$number2 = mysql_num_rows($getmates2);
if ($number1 == 0 && $number2 == 0) {
echo "You have no friend updates";
} else {
if ($number1 >= 1 && $number2 == 0) {
while($mates = mysql_fetch_array($getmates)) {
$getupdates = mysql_query("SELECT * FROM friendupdates WHERE username = '$mates[from_user]' ORDER BY id DESC") or die(mysql_error());
while($updates = mysql_fetch_array($getupdates)) {
$getfirstlast = mysql_query("SELECT * FROM users WHERE username = '$updates[username]'");
$firstlast = mysql_fetch_array($getfirstlast);
echo "<tr><td align='center'>On $updates[date] at $updates[time]<br /><a href='profile.php?user=$firstlast[username]'>$firstlast[firstname] $firstlast[lastname]</a> $updates[action]";
echo "<br /><br /></td></tr>";
}
}
} else {
if ($number1 == 0 && $number2 >= 1) {
while($mates2 = mysql_fetch_array($getmates2)) {
$getupdates2 = mysql_query("SELECT * FROM friendupdates WHERE username = '$mates2[to_user]' ORDER BY id DESC") or die(mysql_error());
while($updates2 = mysql_fetch_array($getupdates2)) {
$getfirstlast2 = mysql_query("SELECT * FROM users WHERE username = '$updates2[username]'");
$firstlast2 = mysql_fetch_array($getfirstlast2);
echo "<tr><td align='center'>On $updates2[date] at $updates2[time]<br /><a href='profile.php?user=$firstlast2[username]'>$firstlast2[firstname] $firstlast2[lastname]</a> $updates2[action]";
echo "<br /><br /></td></tr>";
}
}
}
}
}
echo "</table><br /><br />";
}
?>
So you know, to_user means the person that received the friend request, and from_user means the person that sent the friend request.
This is what happens with this code:
http://www.vincesgames.com/updatesscreenie.png
I have put circles around to show you what has happened. It has ordered them by usernames, but I don't want that, I want them to be in order of the date they happened (the date they got inserted into the database).
Does anyone have any idea how I can do this? I'm really confused. :S
Any help appreciated.
Thank you,
Vince.
<?
include "config.php";
if ($logged[username]) {
echo "<center><font class='normaltext'><u>Friend Updates</u><br /><br /></center><table border='0' cellspacing='2' cellpadding='0' class='normaltext'>";
$username = $logged['username'];
$getmates = mysql_query("SELECT * FROM friends WHERE to_user = '$username' AND confirmed = 'True'") or die(mysql_error());
$getmates2 = mysql_query("SELECT * FROM friends WHERE from_user = '$username' AND confirmed = 'True'") or die(mysql_error());
$number1 = mysql_num_rows($getmates);
$number2 = mysql_num_rows($getmates2);
if ($number1 == 0 && $number2 == 0) {
echo "You have no friend updates";
} else {
if ($number1 >= 1 && $number2 == 0) {
while($mates = mysql_fetch_array($getmates)) {
$getupdates = mysql_query("SELECT * FROM friendupdates WHERE username = '$mates[from_user]' ORDER BY id DESC") or die(mysql_error());
while($updates = mysql_fetch_array($getupdates)) {
$getfirstlast = mysql_query("SELECT * FROM users WHERE username = '$updates[username]'");
$firstlast = mysql_fetch_array($getfirstlast);
echo "<tr><td align='center'>On $updates[date] at $updates[time]<br /><a href='profile.php?user=$firstlast[username]'>$firstlast[firstname] $firstlast[lastname]</a> $updates[action]";
echo "<br /><br /></td></tr>";
}
}
} else {
if ($number1 == 0 && $number2 >= 1) {
while($mates2 = mysql_fetch_array($getmates2)) {
$getupdates2 = mysql_query("SELECT * FROM friendupdates WHERE username = '$mates2[to_user]' ORDER BY id DESC") or die(mysql_error());
while($updates2 = mysql_fetch_array($getupdates2)) {
$getfirstlast2 = mysql_query("SELECT * FROM users WHERE username = '$updates2[username]'");
$firstlast2 = mysql_fetch_array($getfirstlast2);
echo "<tr><td align='center'>On $updates2[date] at $updates2[time]<br /><a href='profile.php?user=$firstlast2[username]'>$firstlast2[firstname] $firstlast2[lastname]</a> $updates2[action]";
echo "<br /><br /></td></tr>";
}
}
}
}
}
echo "</table><br /><br />";
}
?>
So you know, to_user means the person that received the friend request, and from_user means the person that sent the friend request.
This is what happens with this code:
http://www.vincesgames.com/updatesscreenie.png
I have put circles around to show you what has happened. It has ordered them by usernames, but I don't want that, I want them to be in order of the date they happened (the date they got inserted into the database).
Does anyone have any idea how I can do this? I'm really confused. :S
Any help appreciated.
Thank you,
Vince.