php prepared simple page jump function to achieve the code

  • 2020-11-20 06:02:48
  • OfStack

Without further ado, just code it

// Linked database ' The query 
mysql_connect('localhost','username','userpwd')or die(" Database link failed ".mysql_error());
mysql_select_db(' The library ');
mysql_query('set names utf8');
$sql1="select * from user ";
$query1=mysql_query($sql1);
$count=array();
while($row=mysql_fetch_assoc($query1)){
    $count[]=$row;
}
$totalnews=count($count);
// judge page
if($_GET['page']){
    $page=$_GET['page'];
}else{
    $page=1;
}
$start=($page-1)*$newnum;
   $sql="select * from user limit $start,$newnum";
   $query=mysql_query($sql);
   $ret=array();
   while($row=mysql_fetch_assoc($query)){
       $ret[]=$row;
       }
?>
// Table style 
<div id="wrap" style="width:100%;height:100%; ">
   <table border="1px"; style="border-collapse:collapse; border:1px solid #000; width:100%;height:100%">
     <?php foreach ($ret as $key=>$value){ ?>
       <tr>
           <td><?php echo $value['id'] ?></td>
           <td><?php echo $value['username'] ?></td>
           <td><?php echo $value['pwd'] ?></td>
           <td> delete | Modify the </td>
       </tr>
     <?php } ?>
     <tr >
// Page jump 
           <td colspan="4" align="center"><a href="upload.php?page=1"> Home page </a> <a href="upload.php?page=<?php echo $lastpage ?>"> on 1 page </a> <?php echo $page; ?>/<?php echo $pagenum; ?> <a href="upload.php?page=<?php echo $nextpage; ?>"> Under the 1 page </a> <a href="upload.php?page=<?php echo $pagenum ?>"> back </a><input type="text" name="text" /><input type="button" value=" jump " onclick="check(this)"/>
           </td>
     </tr>
   </table>
</div>

Related articles: