I've written the following code that works very well. Basically, I pass 2 parameters (Among others) that determine the # of results per page, and which page we're on. Then, I build a dynamic query that returns the records I want. Check it out.
/
$num_results = results per page
$s_page = which page of results we're on
/
//I have already queried my DB to find the total # of matching records
if($num_results)
$perpage = $num_results;
else
$perpage = 5;
$rows = mysql_num_rows($result);
$low = $perpage * $s_page;
$high = $low + $perpage;
$MAXPAGES = floor($rows/($perpage + 1));
$ismax = 0;
if($high >= $rows) {
$high = $rows;
$ismax = 1;
}
if(@!$sort_dir || $sort_dir == "DESC")
$sort_dir = "ASC";
elseif($sort_dir == "ASC")
$sort_dir = "DESC";
if(@!$sortby)
$sortby = "username";
if($sortby == "rname")
$sortby = "show_name DESC, last_name $sort_dir, first_name";
$sql = "SELECT * FROM tg_users WHERE $select ORDER BY $sortby $sort_dir LIMIT $low, $perpage";
Displaying matches <?=$low+1?>-<?=$high?> of <?=$rows?><BR>
for($i=0;$i<$MAXPAGES;$i++) {
echo "<A HREF=\"$PHP_SELF?s_page=$i&num_results=$numresults\">$i</A>\n";
}
Voila!