SoFunction
Updated on 2025-04-13

Simple paging program for php

=="") 
  $page=1; 

   
//Calculate the record offset
$offset=$pagesize*($page-1); 
//Get records
$res=mysql_query("select username,pass,mail,add_time from buyer order by add_time limit $offset,$pagesize" ,$db); 
//Running display record
  if ($myrow = mysql_fetch_array($res)) 
  { 
   $i=0; 
?> 
</p> 
<p>  </p> 
<table width="100%" border="0" align="center"> 
  <tr> 
    <td width="40%" height="30"> </td> 
<td width="20%" align="center"><span class="STYLE1">User Information Management<br>
          <br> 
    </span></td> 
    <td width="15%"> </td> 
    <td><? $time=date ("Y-l-F H:i:s");echo $time;?> 
       </td> 
  </tr> 
</table> 
<div align="center"> 
  ------------------------------------------------------------- 
</div> 
<table width="90%" border="1" align="center" cellpadding="0" cellspacing="0"> 
  <tr> 
<td width="10%" height="24" bgcolor="#cccccc"><div align="center">serial number</div></td>
<td width="20%" bgcolor="#cccccc"><div align="center">username</div></td>
<td width="20%" bgcolor="#cccccc"><div align="center">Password</div></td>
<td width="30%" bgcolor="#cccccc"><div align="center">email</div></td>
<td bgcolor="#cccccc"><div align="center">Add time</div></td>
  </tr> 
  <?php 
do  

  $i++; 
?> 
  <tr> 
    <td width="10%"><div align="center"><?php echo $i;?></div></td> 
    <td><div align="center"><font size="2"> <?php echo $myrow['username'];?></font></div></td> 
    <td><div align="center"><font size="2"><?php echo $myrow['pass'];?></font></div></td> 
    <td><div align="center"><font size="2"><?php echo $myrow['mail'];?></font></div></td> 
    <td><div align="center"><font size="2"><?php echo $myrow['add_time'];?></font></div></td> 
  </tr> 

  <?php 

while ($myrow = mysql_fetch_array($res)); 
  echo "</table>" ; 

//Display the total number of pages
echo "<div align='center'>There are totals".$pages."pages.")<br>";
//Display the number of pages
for ($i=1;$i<$page;$i++) 
echo "<a href='$SELF_PHP?page=".$i."'>Page ".$i ."Page</a> ";
echo "Chapter".$page."Page  ";
for ($i=$page+1;$i<=$pages;$i++) 
echo "<a href='$SELF_PHP?page=".$i."'>Page ".$i ."Page</a> ";
  echo "<br>"; 
//Display number of pages to go
  echo "<form action='$SELF_PHP' method='post'> "; 
//Calculate the page values ​​of the home page, previous page, next page, and last page
$first=1; 
$prev=$page-1; 
$next=$page+1; 
$last=$pages; 
if ($page>1) 

echo "<a href='$SELF_PHP?page=".$first."'>Home</a> ";
echo "<a href='$SELF_PHP?page=".$prev."'>Previous page</a> ";

if ($page<$pages) 

echo "<a href='$SELF_PHP?page=".$next."'>Next page</a> ";
echo "<a href='$SELF_PHP?page=".$last."'>Last Page</a> ";

echo "</form>"; 
echo "</div>"; 
?> 
</table> 
<p> </p> 
</body> 
</html> 
[/code]