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 4 of 4

Thread: limit reults

  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    limit reults

    hello, i have the following code:


    Code:
             <?
    				$get_name = mysql_query("SELECT `id`, `name`, `link`, `value`, `description` from `offers` WHERE `countries` = 'us' LIMIT 25, 50");
     while($namerow = mysql_fetch_array($get_name)) {
      	$id = $namerow["id"];
    	$link = $namerow["link"];
    	$name = $namerow["name"];
    	$amount = $namerow["value"];
    	$desc = $namerow["description"];
    ?>
    and it says limit 25,50 which is supposed to only results 25-50 but instead its showing up 50 results on the page? the page where its limited 0, 25 works fine. also on the pages where its 50,75 its showing some of the same results from the other pages

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    You have misread the documentation.

    The syntax is
    Code:
       ... LIMIT offset, rowcount
    So if you always want 25 rows, always end your LIMIT with 25. All you change is the starting record number ("offset").

  • Users who have thanked Old Pedant for this post:

    markman641 (08-18-2011)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    http://dev.mysql.com/doc/refman/5.5/en/select.html

    With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):

  • Users who have thanked Old Pedant for this post:

    markman641 (08-18-2011)

  • #4
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post
    thanks!!!!
    Last edited by markman641; 08-18-2011 at 09:27 PM.


  •  

    Posting Permissions

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