Php > Databases
Limit the display of records on each page from mysql
Limit the display of records on each page from mysql //A sample function that I made that will limit the number of //rows from mysql to be display each page where $start is //the starting row, $trows is the total number of rows and $rown //is the number of rows to be display each page. $rown ||$start<>intval(0)) { $first="
First
";} else { $first="First"; } return $first; } function previous($start,$trows,$rown) { if ($start >= $trows-intval($trows%$rown)&&$trows>$rown||$start<>intval(0)) { $prev=$start-$rown; $previous="
Previous
"; } else { $previous="Previous"; } return $previous; } function next1($start,$trows,$rown) { if ($start < ($trows-intval($trows%$rown))&&(($start+$rown)-$trows<>"0")) { $next=$start+$rown; $next="
Next
"; } else { $next="Next"; } return $next; } function last($start,$trows,$rown) { if ($start < $trows-intval($trows%$rown)&&(($start+$rown)-$trows<>"0")) { if (($rem=$trows%$rown)==0){$rem=$rown;} $last=intval($trows-$rem); $last="
Last
"; } else { $last="Last"; } return $last; } //end of the functions mysql_connect($host,$user,$password); mysql_select_db($db); $query="select * from $tbl"; $result=mysql_query($query); $numrows=mysql_num_rows($result);//total number of rows equal to $trows; if ($start=="") {$start=0;} $query="$query limit $start,$rown"; //limit output $rown=5 rows starting $start $result=mysql_query($query); print"
Field1
Field2
Field3
Field4
Field5
"; while ($row=mysql_fetch_array($result)) { print"
$row[0]
$row[1]
$row[2]
$row[3]
$row[4]
"; } print"
"; print"
".first($start,$numrows,$rown)."
".previous($start,$numrows,$rown)."
".next1($start,$numrows,$rown)."
".last($start,$numrows,$rown)."
"; ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage