No JS full php process data paging implementation code

  • 2020-05-19 04:26:16
  • OfStack

 
<?php 
// Login page Settings session, when session in name when  
//session_start(); 
//$name = $_SESSION['name']; 
//if (empty($name)){ 
// header("Location: error.php"); 
// exit(); 
//} 
// Process oriented ,  Data paging display  
if(false!=($mysql = mysql_connect(' local mysql', 'mysql The user name ', 'mysql password '))){ 
mysql_query('set names utf8',$mysql); // Sets the encoding in the database  
mysql_select_db(" The database database",$mysql); 
}else{ 
die(" The connection fails "); 
} 


$pageSize = 10; // Page display number  
$rowCount = 0; // Total number of data , Get from the database  

$sqlCount = 'select count(id) from employee'; 
$res1 = mysql_query($sqlCount,$mysql); 

// Fetch the number of data bars  
if(false!=($row=mysql_fetch_row($res1))){ 
$rowCount = $row[0]; 
} 

// Total number of pages , It's calculated  
$pageCount = 0; 
$pageCount = ceil($rowCount/$pageSize); 

// Get the current page  
if(!isset($_GET['pageNow'])){ //  when  get/post Assign default values when both are empty 1 
$pageNow = 1; // The current number of pages  
}elseif(false!=is_numeric($_GET['pageNow']) && $_GET['pageNow']<=$pageCount){ 
$pageNow = $_GET['pageNow']; 
}else{ 
header("Location: ../Error/error.php"); 
exit(); 
} 
// Print paging data  
echo "<div style='margin-left:300px;margin-top:1px;'>"; 
echo "<table style='border:1px;border-style:solid;border-width:1px;border-color:green'>"; 
echo "<tr><th>id</th> <th>name</th> <th>age</th> <th>sex</th> <th>birthday</th> <th> Edit the employees </th> <th> Delete the employee </th> </tr>"; 
$sqList = "select id,name,age,sex,birthday from employee limit ".($pageNow-1)*$pageSize.",".$pageSize; 
$res2 = mysql_query($sqList,$mysql); 
while (false!=($row=mysql_fetch_assoc($res2))){ 
echo "<tr><td>{$row['id']}</td> <td>{$row['name']}</td> <td>{$row['age']}</td> <td>{$row['sex']}</td> <td>{$row['birthday']}</td> <td><a href=#> The editor </a></td> <td><a href=#> delete </a></td></tr>"; 
} 
echo "</table>"; 
// The form controls how many pages are displayed  
echo "<form action=' The current page '>"; 
// on 1 Page button  
if($pageNow>1){ 
$pageUp = $pageNow-1; 
echo "<a href='?pageNow=".$pageUp."'> on 1 page </a> "; 
} 

// Under the 1 Page button  
if($pageNow<$pageCount){ 
$pageDown = $pageNow+1; 
echo "<a href='?pageNow=".$pageDown."'> Under the 1 page </a> <br/>"; 
} 

// back 10 Page button  
if($pageNow-10>0){ 
echo "<a href='?pageNow=".($pageNow-10)."'><<<</a> "; 
} 


// Pass the number of pages currently displayed to this page , And displays the page number button  
for($i=1;$i<=$pageCount;$i++){ 

if($i>$pageNow-2 && $i<$pageNow+6){ 
if($i!=$pageNow){ 
echo "<a href='?pageNow=".$i."'> The first ".$i." page </a> "; 
} 
} 
} 

// forward 10 page  
if($pageNow+10<=$pageCount){ 
echo "<a href='?pageNow=".($pageNow+10)."'>>>></a> "; 
} 

// Displays the current page and the total number of pages  
echo "<br/> The current page ".$pageNow." page / A total of ".$pageCount." page "; 


// The jump page  
echo " Jump to :<input type='text' name='pageNow' id='pageNow' style='width:30px;height:20px'/> page <input type='submit' style='width:37px;height:20px;font-size:11px;' value='go'/>"; 
echo "</form>"; 
echo "</div>"; 
?> 

Related articles: