Jump to content

LIMIT


Kasuke_Akira

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.