Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Post PHP Coding / SQL Databases Help Please!

    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:

    PHP Code:
    <?
    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 == && $number2 == 0) {
    echo 
    "You have no friend updates";
    } else {
    if (
    $number1 >= && $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 == && $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:



    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.
    Last edited by ThisNameWillDo!; 16-03-2010 at 03:21 PM.
    Free Online Games And Videos:
    http://www.vincesgames.com



  2. #2
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    When since you have "order by id desc" there, maybe try "ORDER BY date DESC"?

    I didnt look through the code completely but maybe tht cud help?

    Lew.
    Im not here to be loved, I love to be hated :-}


  3. #3
    Join Date
    Jan 2006
    Location
    Kent
    Posts
    987
    Tokens
    0

    Default

    I find the easiest way to deal with dates and ordering entries in a database is by using a timestamp rather than putting the actual date and time in, then from that timestamp you can convert it into a date and time. Doing this will result in you being able to order properly
    This is our situation and we're happy to be here,
    I wouldn't change this place for anything.


  4. #4
    Join Date
    Jan 2007
    Location
    Wales
    Posts
    2,432
    Tokens
    141

    Latest Awards:

    Default

    Hi, I put ORDER BY id DESC in all the $gets but it still didn't do it? :confused:

    There's no point ordering by date, order by id does it fine.

    Any solutions? Some of the coding must be wrong or in the wrong place?
    Free Online Games And Videos:
    http://www.vincesgames.com



  5. #5
    Join Date
    Dec 2006
    Location
    Kent, UK
    Posts
    627
    Tokens
    138
    Habbo
    Romanity

    Latest Awards:

    Default

    Your $getmates query.... try ordering that by id DESC as well. And also the same with $getmates2. See if that works.
    I also recommend you follow the advice of arranged by date.
    Sangreal / Romanity ~ Habbo UK & USA
    [OurHabbo.Net Owner]
    Lewis. (Formerly xRoyal15)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •