Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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