02-07-2008, 03:30 PM
|
#8 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
The generic code I use, form an image hosting site I built
PHP Code:
//get the total count so we know what we are working with $count_query = mysql_query("SELECT COUNT(id) AS `count` FROM `images` WHERE `uploader` = '$user->id'") or die(mysql_error()); $count_arr = mysql_fetch_array($count_query); $count = $count_arr["count"];
//assign the pages $page = $data->get("page");
//if page not set, set it to zero if($page == "") { $page = 0; } //set this to the number of items you want it to display per page $perpage = 10;
//If there are enough rows to fit on a single page, we dont need any more pages if(mysql_num_rows($count_query) < $perpage) { $pages = 0; } //If there are too many rows, allow for more pages else { $pages=ceil($count / $perpage); } //this is where the page starts in the query $page_start = $perpage * $page; //this is where the page ends $page_end = $page_start + ($perpage);
$sql = mysql_query("SELECT * FROM `images` WHERE `uploader` = '$user->id' ORDER BY `date` DESC LIMIT $page_start,$perpage") or die(mysql_error());
|
|
|
|