<?php
/**
* Created by Coder Meng.
* User:coder Meng
* Date:2016/8/29 10:27
*/
Header"Content-type:text/html;charset=utf-8");
Include_once' config.php ';
/* $sql = "SELECT * from article";
$rs =mysql_query ($sql); * *
$where =‘‘;
$url =‘‘;
$wherelist =Array ();
$urllist ="";
if (!Empty$_get[' Author ')) {
$author =$_get[' Author '];
$wherelist []="Author like '%$author%‘";
$urllist []="&author=$author";
}
if (!Empty$_get[' title ']) {
$title =$_get[' title '];
$wherelist []="Title like '%$title%‘";
$urllist []="&title=$title";
}
if (!Empty$_get[' content ')) {
$content =$_get[' Content ';
$wherelist []="Content like '%$content%‘";
$urllist []="&content=$content";
}
IfCount$wherelist) >0) {
$where =' WHERE '.Implode (' and ',$wherelist);
$url =Implode (‘‘,$urllist);
}
$sql 2 =The Select*From article$where";
$rs =mysql_query ($sql 2);
$sql 1= "SELECT * from article $limit"; (1-1) *10
2, total number of pages=Total Record Count/Number of bars per page
$totlanums =Mysql_num_rows ($RS);101Conforming to the13
1, number of articles per page
$pagesize =2;
//Total number of pages
$maxpage =Ceil ($totlanums/$pagesize);//Maximum page count is also the total number of pages
$page =Isset$_get[' Page '])?$_get[' Page ']:1;
If$page <1) {
$page =1;
}
If$page >$maxpage) {
$page =$maxpage;
}
$start = ($page-1) *$pagesize;
$limit =The limit$start,$pagesize";
$sql 3 =The Select*From article$where $limit";
$rs 3 =mysql_query ($sql 3);
$arr =Array ();
//The principle of paging
/*while ($row = Mysql_fetch_assoc ($rs)) {
$arr [] = $row;
}*/
/* $sql 1= "SELECT * from article limit 10,10"; (1-1) *10
$sql 1= "SELECT * from article limit 20,10"; (1-1) *10*/
?>
<!doctypeHtml>
<Htmllang="EN" >
<Head>
<Metacharset="UTF-8" >
<title>document</Title>
</Head>
<Body>
<Divstyle="Width600pxMargin0Auto">
<Formaction="pagelist.php"Method="Get" >
<TableBorder="1"Width=">"
<Tr>
<Td><Input type= "text" name= "author" value= "<?php echo isset ($_get[' author '])? $_get[' author ']: ';? > "></td>
<td> title: <input type= "text" name= "title" Value= "<?php echo isset ($_get[' title '])? $_get[' title ']: ';? > "></td>
<td> content: <input type= "text" name= "content" value= "<?php echo isset ($_get[' content '])? $_get[' content ']: ';? > "></td>
<td><input type= "Submit" value= "Search" ></td>
</tr>
</table>
</form>
<table border= "1" width= ">"
<tr>
<td> numbering </td>
<td> author </td>
<td> title </td>
<td> content </td>
<td> Operations </td>
</tr>
<?php while ($row = Mysql_fetch_assoc ($rs 3)) {?>
<tr>
<td><?php echo $row [' ID ']?></td>
<td><?php echo $row [' Author ']?></td>
<td><?php echo $row [' title ']?></td>
<td><?php echo $row [' content ']?></td>
<td> Edit | Delete </td>
</tr>
<?php}?>
<tr>
<TD colspan= "5" align= "Center" >
<?php
echo "Current {$page} page/{$maxpage}, total {$totlanums} records";
if ($page >1) {
echo "<a href= ' Pagelist.php?page=1$url ' > Home </a>";
echo "<a href= ' pagelist.php?page=". ($page-1). " $url ' > Prev </a> ';
}
if ($page < $maxpage) {
echo "<a href= ' pagelist.php?page=". ($page + 1). " $url ' > Next </a> ';
echo "<a href= ' pagelist.php?page= $maxpage {$url} ' > Last </a>";
}
?>
</td>
</tr>
</table>
</div>
PHP MySQL database paging and searching