SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict maxy22's Avatar
    Join Date
    Dec 2004
    Location
    here
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Order by Descending

    I have a small script that is fetching data as

    Code:
    $sql=mysql_query("SELECT * FROM messages LIMIT 9");
    while($row=mysql_fetch_array($sql))
    {
    $msg=$row['msg'];
    $mes_id=$row['mes_id'];
    $up=$row['up'];
    $down=$row['down'];
    ?>
    I want to display the fetched data in Descending order based on the value in 'up' for each entry , so I tried that

    Code:
    $sql=mysql_query("SELECT * FROM messages  LIMIT 9 ORDER BY up DESC");
    but I get the error "supplied argument is not a valid MySQL result resource"
    What is the problem here

    Thanks

  2. #2
    SitePoint Addict maxy22's Avatar
    Join Date
    Dec 2004
    Location
    here
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK a quick update, I have got it working I just had to remove that LIMIT 9 from the script

    what exactly does the limit 9 does ? can I remove it permanently ?

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    LIMIT 9 means "return only 9 rows"

    put it back after the ORDER BY, not in front
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict maxy22's Avatar
    Join Date
    Dec 2004
    Location
    here
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    LIMIT 9 means "return only 9 rows"

    put it back after the ORDER BY, not in front
    Thanks for your help
    much appreciated


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
  •