SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do i display the contents of my database starting from last row to the first row. In other words display the last content added to the data base first , then the one before that, then the one before that and on and on.

    The problem im having is understading what is actually returned from the query("select * from <table>);.
    Is it an array of arrays or something else and how do i control it.

    And does anyone know where i can find examles or details of all or at least some of the mysql/php functions. please someone help me, new guy in distress.

  2. #2
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lets say you have an auto incrementing ID field ..

    which goes from 1 and increases for every row you add

    so, now you're query is something like "SELECT * FROM table WHERE asdf='boo'" ... this will get you the one with the lower ID first.. so you can use an ORDER BY statement to do "SELECT * FROM table WHERE asdf='boo' ORDER BY ID DESC" .. which will order results by the ID in descending order
    cogito, ergo sum

  3. #3
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's an example:

    PHP Code:

    $table 
    table_name;
    $sql "SELECT * FROM $table ORDER BY id DESC";
    $result mysql_query($sql);
    while(
    $row mysql_fetch_array($result)){
    $name $row['name'];
    $phone $row['phone'];

    echo(
    "$name$phone");

    that will order all your tables from last to first.. if you have an ID auto-incrament field... if you don't.. set one up!
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  4. #4
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks alot you guys. I understand what you both are saying. I guess i was spending too much time worring about the result array and not the kind of array i was quering for.
    Ok im going to try this out and see what happens, thanks again

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    For all the information you can handle on this stuff, check out my article Building a Database-Driven Web Site using PHP and MySQL.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

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