MySQL & PHP- Paging statement
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
// MySQL & PHP- Paging statement
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Here we go ->
<?
$MONTH=$_REQUEST['MONTH'];
$pos = $_REQUEST['no']; // Number input by user
$display = “10″;
$gettot = mysql_query(”SELECT * FROM user_services where BALANCE !=” and MONTH=’$MONTH’”);
$totnum = @mysql_num_rows($gettot);
$result = mysql_query(”SELECT * FROM user_services where NRIC != ” and BALANCE !=” and MONTH=’$MONTH’ order by DATE LIMIT $pos, $display”);
?>
<?
//You can put this code at the bottom of your PHP script, because this is to display the next, previous and page number links
$num_pages = ceil($totnum / $display);
if($totnum > $display) {
// this is previous links
if($pos > 0){
echo “<A href=\”result_view_NRIC .php?no=”.($pos – $display) .”&NRIC =$NRIC \”><prev</A> | “;
} else {
echo “<prev | “;
}
// this is no page links
$i = 0;
while($i < $num_pages){
$page = $i * $display;
$i++;
if($page != $pos){
echo “<A href=\”result_view_NRIC .php?no=$page&NRIC =$NRIC \”>$i</A> | “;
} else {
echo “$i | “;
}
}
// this is next links
if($pos < (($num_pages – 1) * $display)){
echo “<A href=\”result_view_NRIC .php?no=” . ($pos + $display) . “&NRIC =$NRIC \”>next></A>”;
} else {
echo “next>”;
}
}
?>
About this entry
You’re currently reading “MySQL & PHP- Paging statement,” an entry on Xyiry PHP Blog | Where Open Source Lives
- Published:
- 08.11.07 / 12am
- Category:
- MySQL
No comments
Jump to comment form | comments rss [?] | trackback uri [?]