PHP Help with pagination
am 29.01.2010 07:48:20 von Karl DeSaulniers--Apple-Mail-2-825175890
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Hey nagendra,
I tried to post this a while ago, but it may be too long for the list.
if ($Submit) { // perform search only if correct form was entered.
$db = mysql_connect ($Host, $User, $Password);
mysql_select_db ($DBName) or die ("Cannot connect to database");
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['pg']) or !is_numeric($_GET['pg'])) {
//we give the value of the starting row to 1 because this is the
first page
$pg = 1;
//otherwise we take the value from the URL
} else {
$pg = $_GET['pg'];
}
?>
selection from the previous page that called this one.
if ($fieldTwentyOne == 'All Users Last Login Date') {
$fieldTwentyOne = "%";
}
$srch="%".$Submit."%";
?>
/// Variables
$max_results = 5; /// Number of results per page
$min = (($pg * $max_results) - $max_results);
?>
/// Count total
$query_total_users = "SELECT COUNT(*) as Num FROM users";
$totals = mysql_result(mysql_query($query_total_users, $db),0);
$total_pgs = ceil($totals / $max_results);
?>
$query_UserLastLogin = "SELECT * FROM users WHERE UserLastLogin LIKE
'$fieldTwentyOne' ";
$UserLastLogin = mysql_query($query_UserLastLogin, $db) or die
(mysql_error());
if(!get_magic_quotes_gpc()) { $UserLastLogin = stripslashes
($UserLastLogin); }
$row_UserLastLogin = mysql_fetch_assoc($UserLastLogin);
?>
/// Page limiter & result builder
// Access table properties
$query_users = "SELECT * FROM users LIMIT $min, $max_results";
$result = mysql_query($query_users, $db) or die(mysql_error());
$num_sql = mysql_numrows($result);
if ($result) {
// Build paging
if($pg > 1) {
$prev = ($pg - 1); // Previous Link
$paging = "
$prev."'>Previous page ";
//$paging = "Previous
page";
}
for($j = 1; $j <= $total_pgs; $j++) { /// Numbers
$paging .= "
$Submit."&pg=".$j."'> ".$j." ";
//$paging .= " "; }}
}
if($pg < $total_pgs) {
$next = ($pg + 1); // Next Link
$paging .= "
$Submit."&pg=".$next."'> Next page";
}
?>
//--------------------
In my html I have a table cel displaying info
For the page numbers:
For showing current page and database totals:
Num_sql Rows: $num_sql?>
Number of Users:
Total Pages:
php echo $total_pgs?>
Number of Results: >
Viewing page of
Then I close the html and php
} // End if($Submit)
?>
Use this if you want, I took bits and pieces and put this together
for you, but hope that helps.
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-2-825175890--