#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    San Juan, Argentina
    Posts
    6
    Rep Power
    0
    Hi guys. I'm Henry from Argentina.
    You know that by making this:

    //$table, $id comes from a form.php3 with some values
    $result=mysql_db_query("$db","select * from $table where id=$id);
    //the i gotta type this
    while($data=mysql_fetch_array($result))
    {
    //i must show all data from $table
    }

    BUT... what happens if i wanna show the data in inverse order than the order that the table has. This idea came up to mi mind cause i've a $table with messages posted by users, so i wanna show the newest message first and the oldest at bottom...
    With this while i've shown you, the oldest appears first... What can i do ?

    I send ya the structure of my table:

    from char(100)
    to char(100)
    message mediumtext
    id int(1)

    the id field can contain 3 types. If message id is 1 i must show this message in one part of the page, if 2, in other section, and if the message id is 3 i must show in another section, but i must always show the newest message at top of the section. Could i add another field to the table, so i can generate a better algorithm for making this possible ?

    Thanks in advance. See ya.


    ------------------
    Henry - Argentina
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    You should be able to add a field with date and toime submitted then could add another clause to your select statement like:

    $result=mysql_db_query("$db","select * from $table where id=$id ORDER by date desc);
  4. #3
  5. Senior Member
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2000
    Location
    Enschede, The Netherlands
    Posts
    1,527
    Rep Power
    16
    If I get this right you have 3 sections where messages can be showed and each section has to have the newest at the top?

    I would rename the current column 'id' to 'section' and add another column in your database called 'id', which is auto incrementing (so the latest message has the highest id)

    Then make the following query:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>
    ...
    $table = ""; // whatever you use
    $section = '1'; // for section 1
    $result = mysql_query( "SELECT * FROM $table WHERE section='$section' ORDER BY id DESC" );
    ...
    [/quote]

    The message with the highest id (also the newest) will be shown first...

    Mirax

Similar Threads

  1. Codepupil
    By Adachic in forum C Programming
    Replies: 3
    Last Post: February 6th, 2004, 06:50 PM
  2. Loading data from text files
    By Manso in forum MySQL Help
    Replies: 1
    Last Post: January 28th, 2004, 04:53 AM
  3. post data to new window then do redirect
    By theDano in forum PHP Development
    Replies: 2
    Last Post: January 24th, 2004, 06:08 PM
  4. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 06:19 PM
  5. my comp sux lately , need help from pro's
    By Hykinsel007 in forum Windows Help
    Replies: 2
    Last Post: January 5th, 2004, 01:52 PM

IMN logo majestic logo threadwatch logo seochat tools logo