$wherelist=array(); $urlist=array(); if(!empty($_GET['title'])) { $wherelist[]=" title like '%".$_GET['title']."%'"; $urllist[]="title=".$_GET['title']; } if(!empty($_GET['keywords'])) { $wherelist[]=" keywords like '%".$_GET['keywords']."%'"; $urllist[]="keywords=".$_GET['keywords']; }if(!empty($_GET['author'])) { $wherelist[]=" author like '%".$_GET['author']."%'"; $urllist[]="author=".$_GET['author']; } $where=""; if(count($wherelist)>0) { $where=" where ".implode(' and ',$wherelist); $url='&'.implode('&',$urllist); } //分頁的實現(xiàn)原理 //1.獲取數(shù)據(jù)表中總記錄數(shù) $sql="select count(*) from news $where "; $result=mysql_query($sql); $totalnum=mysql_num_rows($result); //每頁顯示條數(shù) $pagesize=5; //總共有幾頁 $maxpage=ceil($totalnum/$pagesize); $page=isset($_GET['page'])?$_GET['page']:1; if($page <1) { $page=1; } if($page>$maxpage) { $page=$maxpage; } $limit=" limit ".($page-1)*$pagesize.",$pagesize"; $sql1="select * from news {$where} {$limit}"; //$sql1="select * from news {$where} {$limit}"; $res=mysql_query($sql1); ?> <form action="searchpage.php" method="get"> 標(biāo)題:<input type="text" name="title" value="<?php echo $_GET['title']?>" size="8"> 關(guān)鍵字<input type="text" name="keywords" value="<?php echo $_GET['keywords']?>" size="8"> 作者:<input type="text" name="author" value="<?php echo $_GET['author']?>" size="8"> <input type="button" value="查看全部" onclick="window.location='searchpage.php'"> <input type="submit" value="搜索"> </form> <table border="1" width="1000" align="center"> <tr> <td>編號</td> <td>標(biāo)題</td> <td>關(guān)鍵字</td> <td>作者</td> <td>日期</td> <td>內(nèi)容</td> </tr> <?php while($row= mysql_fetch_assoc($res)){?> <tr> <td><?php echo $row['id'] ?></td> <td><?php echo $row['title'] ?></td> <td><?php echo $row['keywords'] ?></td> <td><?php echo $row['author'] ?></td> <td><?php echo date("Y-m-d H:i:s",$row['addtime']) ?></td> <td><?php echo $row['content'] ?></td> </tr> <?php }?> <tr> <td colspan="6"> <?php echo " 當(dāng)前{$page}/{$maxpage}頁 共{$totalnum}條"; echo " <a href='searchpage.php?page=1{$url}'>首頁</a> "; echo "<a href='searchpage.php?page=".($page-1)."{$url}'>上一頁</a>"; echo "<a href='searchpage.php?page=".($page+1)."{$url}'>下一頁</a>"; echo " <a href='searchpage.php?page={$maxpage}{$url}'>尾頁</a> "; ?> </td> </tr> </table>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Grass Wonder Build Guide | Uma Musume Pretty Derby
4 weeks ago
By Jack chen
Roblox: 99 Nights In The Forest - All Badges And How To Unlock Them
3 weeks ago
By DDD
Uma Musume Pretty Derby Banner Schedule (July 2025)
4 weeks ago
By Jack chen
RimWorld Odyssey Temperature Guide for Ships and Gravtech
3 weeks ago
By Jack chen
Windows Security is blank or not showing options
4 weeks ago
By 下次還敢

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)