Re: LIMIT() function example

From: Date: Thu, 17 Oct 2002 19:50:25 +0000
Subject: Re: LIMIT() function example
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120391@lists.php.net to get a copy of this message
> Can anybody give me an example on how to use the limit() function of MySQL > to build a paging script with PHP ? > > If anybody have an example It would be great! LIMIT is simple. LIMIT m,n where 'm' is the row number to start at, and 'n' is how many rows after that to return. So, in a 'paging' example, you would keep a variable of how many results per page you want and use some math to create your LIMIT. You would keep a second variable, $page, that is passed in the URL or form that tells you what page you are on. You'd start off at page zero. if(!isset($page)) { $page = 0; } $num_per_page = 10; $start = $page * $num_per_page; $end = $start + $num_per_page; $result = mysql_query("SELECT ... LIMIT $start,$end"); Use your previous and next links to increment/decrement $page accordingly. ---John Holmes...

« previous php.general (#120391) next »