The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 7 of 7

Thread: php/mysql limit function, help

  1. #1

    php/mysql limit function, help

    Hey guys and gals.
    I'm trying to pull the top two rows off of my mysql database through php, sorting by ID. I'm just having a sliiiight problem doing it. This is the code I'm using to query the database at the moment.

    PHP Code:
    $query mysql_query" SELECT * FROM mainpage WHERE page = 1 ORDER BY ID DESC LIMIT 0 , 2 " ); 

  2. #2
    Quote Originally Posted by xxviii
    Hey guys and gals.
    I'm trying to pull the top two rows off of my mysql database through php, sorting by ID. I'm just having a sliiiight problem doing it. This is the code I'm using to query the database at the moment.

    PHP Code:
    $query mysql_query" SELECT * FROM mainpage WHERE page = 1 ORDER BY ID DESC LIMIT 0 , 2 " ); 
    PHP Code:
     $query mysql_query" SELECT * FROM mainpage WHERE page = 1 ORDER BY id DESC LIMIT 2 " ); 

  3. #3
    yeah what he said

  4. #4
    Actually if you want the top 2, as in the first two, it would need to be:
    PHP Code:
     $query mysql_query("SELECT * FROM mainpage WHERE page=1 ORDER BY id ASC LIMIT 2"); 

  5. #5
    Thanks guys. I did that before but obviously I did something wrong because it gave me an error

    Thank you

  6. #6
    If I remember correctly, to select a range (for example 2,4) you need to put brackets around the numbers:

    PHP Code:
     $query mysql_query" SELECT * FROM mainpage WHERE page = 1 ORDER BY ID DESC LIMIT (0,2) " ); 
    But since 0,2 is the same as 2, just use LIMIT 2 as said above.
    Wait, what?

  7. #7
    Thanks voets

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012