Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Simple quiestion...

    well .. it's not that simple to me ... ok ... where it is ...

    my problem is very simple .. am pulling some things from database and display them in the table. but i want only newest for example 5 items to appear. Well i did pull all the items form the database ... and that's cool, now how do i count them and stop after 5 items ?

    can anyone help,

    I have tried i think just about anything i could find and try.. and still could not get it right.

    Please help me ...

    Here is piece of code i have written up ...

    ----------------------------------------------

    PHP Code:
    $query "SELECT * FROM links ORDER BY id DESC";
    $result mysql_query$query$link );

    while (
    $counter 5)
     {
            while(
    $r=mysql_fetch_array($result))
                    {    
        
    $cat=$r["cat"];
        
    $url=$r["url"];

    echo 
    "<span class='body'><a href='http://$url' target='_blank'>$url</a> - $cat<br></span>";
    }
    $counter ++;
    break;

    --------------------------------

    What am i doing wrong ?

    thanks in advance

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lake Forest, CA
    Posts
    259
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use this...

    mysql_query("SELECT * FROM links ORDER BY total DESC")
    The Wizzard
    OC Motor Cars | OC Auto Sports (Coming Soon!)

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lake Forest, CA
    Posts
    259
    Thanks
    0
    Thanked 0 Times in 0 Posts
    of course you have to have "total" in your database, someone else in here can help you from here, i am pretty weak past this point.
    The Wizzard
    OC Motor Cars | OC Auto Sports (Coming Soon!)

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Ok for starters you obviously did not read the announcement I posted at the top of this forum. Post SQL questions in the MySQL forum.

    http://www.codingforums.com/showthre...&threadid=4181


    As for the answer to your question you simply need to use the LIMIT function.


    $query = "SELECT * FROM links ORDER BY id DESC LIMIT 5";

    And now I will move this thread to the proper forum.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thank you ..

    thank you all for such prompt answers .. and to Spookster i thought it the answer would lie more in php than mysql thats why i posted here.

    my appolgies.

    HormonX


  •  

    Posting Permissions

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