Kasuke_Akira Posted February 12, 2007 Share Posted February 12, 2007 I was under the impression that stating something like 'LIMIT 0,10' Would mean the first 10 entries in the database would be selected and then displayed. This works on the first page I have, but on just about every other pages, (when I increment it by ten: 'LIMIT 11,20, etc) There are sometimes more than 10 displaying, and many times the amount seems random. I have a little script that is creating links to 'pages' generated by the amount of entries, and 10 to a page. In my site address when the value get passed, the are correctly incremented, so I know I don't have something like 'LIMIT 11,25' in some place. All LIMIT instances are increments of 10. So I was wondering if anyone thought there might just be some conflict in coding, or maybe they have an SQL reason as this is happening. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 We'd need to see the code. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 12, 2007 Share Posted February 12, 2007 That is down to the semantics of teh limit clause... LIMIT 0,10 says get ten rows starting from row 0 of teh result set. LIMIT 11,20 says get 20 rows starting at row 11 of the result set. FIRST NUMBER is the starting row LAST number is the actual number of rows to return. Quote Link to comment Share on other sites More sharing options...
Kasuke_Akira Posted February 12, 2007 Author Share Posted February 12, 2007 $ret_rows = mysql_query("SELECT * FROM posts"); $num_rows = mysql_num_rows($ret_rows); if ($num_rows > 10) { echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=3><TR><TD ALIGN=right>"; echo "<B>Page:</B> "; $num_pages = ($num_rows / 10) + 1; //Determining how many 'pages' based on table entries in database for ($x = 1; $x < $num_pages; $x++) { $limit_1 = ($x * 10) - 10; //Min LIMIT $limit_2 = $x * 10; //Max LIMIT $page_limit = "$limit_1,$limit_2"; //Setting LIMIT if ($x == 1) { echo "<A HREF=index.php?main=1&limit=$page_limit>$x</A>"; }else{ echo " | <A HREF=index.php?main=1&limit=$page_limit>$x</A>"; } That is the code that generates the pages. Quote Link to comment Share on other sites More sharing options...
Kasuke_Akira Posted February 12, 2007 Author Share Posted February 12, 2007 So the last number should always be ten? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 12, 2007 Share Posted February 12, 2007 There's no SQL using a LIMIT in there. Post the code where this happens: "There are sometimes more than 10 displaying, and many times the amount seems random." Edit: Toon is right. Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 12, 2007 Share Posted February 12, 2007 So the last number should always be ten? Yup. The LIMIT syntax is LIMIT offset,amount or LIMIT amount OFFSET offset Quote Link to comment Share on other sites More sharing options...
Kasuke_Akira Posted February 12, 2007 Author Share Posted February 12, 2007 Hah thanks, that makes sense now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.