當前位置:首頁 » 編程語言 » php查詢分頁

php查詢分頁

發布時間: 2022-06-04 18:20:49

php對查詢多個表的結果分頁

添加一個參數: page
起始記錄= page * 每頁條數
sql查詢的時候:在SQL查詢語句加上: limit 起始記錄,10條

㈡ PHP對查詢結果分頁,查詢結果的二次分頁

你這個問題很簡單,就像他們說的一樣吧上次查詢的條件保存下來,吧這個查詢條件,按照url模式寫出來。例如:$a='a=2&s=3&c=9'; 吧你的查詢條件賦值給一個變數,然後吧這個變數給你的頁面url,這樣就能在url中集成查詢條件,但是這個表單就必須吧提交方式改成get。否則無法正常使用。

㈢ 在php中如何對多條記錄進行分頁

方法一:講sql查詢進行分頁進行,需要調用幾個函數,具體見腳本
1.pager.class.php

<?php

class pager {
public $sql; //SQL查詢語句
public $datanum; //查詢所有的數據總記錄數
public $page_size; //每頁顯示記錄的條數
protected $_errstr;
protected $_conn;
protected $_query_id;

public function query($query)///這個函數有問題,暫時可以不用
{
$ret = false;
if (!empty($query)) {
if ($this->_conn === false || !is_resource($this->_conn)) {
warningLog(__METHOD__ . ': query sql with no connection', true);
return false;
}
$this->_query_id = @mysql_query($query, $this->_conn);
if ($this->_query_id === false) {
$this->_errstr = @mysql_error();
$ret = false;
} else {
$this->_errstr = 'SUCCESS';
$ret = $this->_query_id;
}
}
$msg = ($ret === false) ? 'false' : strval($ret);
debugLog(__METHOD__.": [$msg] returned for sql query [$query]");
return $ret;
}
function __construct($sql,$page_size) {
$result = mysql_query($sql);
$datanum = mysql_num_rows($result);
$this->sql=$sql;
$this->datanum=$datanum;
$this->page_size=$page_size;
}

//當前頁數
public function page_id() {
if($_SERVER['QUERY_STRING'] == ""){
return 1;
}elseif(substr_count($_SERVER['QUERY_STRING'],"page_id=") == 0){
return 1;
}else{
return intval(substr($_SERVER['QUERY_STRING'],8));
}
}

//剩餘url值
public function url() {
if($_SERVER['QUERY_STRING'] == ""){
return "";
}elseif(substr_count($_SERVER['QUERY_STRING'],"page_id=") == 0){
return "&".$_SERVER['QUERY_STRING'];
}else{
return str_replace("page_id=".$this->page_id(),"",$_SERVER['QUERY_STRING']);
}
}

//總頁數
public function page_num() {
if($this->datanum == 0){
return 1;
}else{
return ceil($this->datanum/$this->page_size);
}
}
//資料庫查詢的偏移量
public function start() {
return ($this->page_id()-1)*$this->page_size;
}

//數據輸出
public function sqlquery() {
return $this->sql." limit ".$this->start().",".$this->page_size;
}

//獲取當前文件名
private function php_self() {
return $_SERVER['PHP_SELF'];
}

//上一頁
private function pre_page() {
if ($this->page_id() == 1) { //頁數等於1
return "<a href=".$this->php_self()."?page_id=1".$this->url().">上一頁</a> ";
}elseif ($this->page_id() != 1) { //頁數不等於1
return "<a href=".$this->php_self()."?page_id=".($this->page_id()-1).$this->url().">上一頁</a> ";
}
}

//顯示分頁
private function display_page() {
$display_page = "";
if($this->page_num() <= 10){ //小於10頁
for ($i=1;$i<=$this->page_num();$i++) //循環顯示出頁面
$display_page .= "<a href=".$this->php_self()."?page_id=".$i.$this->url().">".$i."</a> ";
return $display_page;
}elseif($this->page_num() > 10){ //大於10頁
if($this->page_id() <= 6){
for ($i=1;$i<=10;$i++) //循環顯示出頁面
$display_page .= "<a href=".$this->php_self()."?page_id=".$i.$this->url().">".$i."</a> ";
return $display_page;
}elseif(($this->page_id() > 6) && ($this->page_num()-$this->page_id() >= 4)){
for ($i=$this->page_id()-5;$i<=$this->page_id()+4;$i++) //循環顯示出頁面
$display_page .= "<a href=".$this->php_self()."?page_id=".$i.$this->url().">".$i."</a> ";
return $display_page;
}elseif(($this->page_id() > 6) && ($this->page_num()-$this->page_id() < 4)){
for ($i=$this->page_num()-9;$i<=$this->page_num();$i++) //循環顯示出頁面
$display_page .= "<a href=".$this->php_self()."?page_id=".$i.$this->url().">".$i."</a> ";
return $display_page;
}
}
}

//下一頁
private function next_page() {
if ($this->page_id() < $this->page_num()) { //頁數小於總頁數
return "<a href=".$this->php_self()."?page_id=".($this->page_id()+1).$this->url().">下一頁</a> ";
}elseif ($this->page_id() == $this->page_num()) { //頁數等於總頁數
return "<a href=".$this->php_self()."?page_id=".$this->page_num().$this->url().">下一頁</a> ";
}
}

// 設置分頁信息
public function set_page_info() {
$page_info = "共".$this->datanum."條 ";
$page_info .= "<a href=".$this->php_self()."?page_id=1".$this->url().">首頁</a> ";
$page_info .= $this->pre_page();
$page_info .= $this->display_page();
$page_info .= $this->next_page();
$page_info .= "<a href=".$this->php_self()."?page_id=".$this->page_num().$this->url().">尾頁</a> ";
$page_info .= "第".$this->page_id()."/".$this->page_num()."頁";
return $page_info;
}

}
?>

2.腳本2:

<?php
//類的用法
// 讀取分頁類
include("pager.class.php");
// 資料庫連接初始化
// $db = new mysql();
$impeach_host = '10.81.43.139';
$impeach_usr = 'vmtest15';
$impeach_passwd = 'vmtest15';
$impeach_name = 'ufeature';
$impeach_con = mysql_connect($impeach_host, $impeach_usr, $impeach_passwd) or
die("Can't connect ".mysql_error());
mysql_select_db($impeach_name, $impeach_con);
// 這是一個sql查詢語句,並得到查詢結果
$sql = "select word from ufeature.spam_accuse_word_list where flag='0'";
// 分頁初始化
$page = new pager($sql,20);
// 20是每頁顯示的數量
// $res_1 = mysql_query($sql) or
// die("Can't get result ".mysql_error());

$result=mysql_query($page->sqlquery());
while($info = mysql_fetch_array($result,MYSQL_ASSOC)){

// while($info = mysql_fetch_array($res_1, MYSQL_ASSOC)){
echo $info["word"]."<br/>";
}
// 頁碼索引條
echo $page->set_page_info();

?>

方法二:使用ajax的方法
1、首先了解SQL語句中的limit用法

SELECT * FROM table …… limit 開始位置 , 操作條數 (其中開始位置是從0開始的)

例子
取前20條記錄:SELECT * FROM table …… limit 0 , 20
從第11條開始取20條記錄:SELECT * FROM table …… limit 10 , 20
LIMIT n 等價於 LIMIT 0,n。
如select * from table LIMIT 5; //返回前5行,和select * from table LIMIT 0,5一樣
2、分頁原理
所謂分頁顯示,也就是講資料庫中的結果集,一段一段顯示出來
怎麼分段,當前在第幾段 (每頁有幾條,當前再第幾頁)
前10條記錄:select * from table limit 0,10
第11至20條記錄:select * from table limit 10,10
第21至30條記錄:select * from table limit 20,10
分頁公式:
(當前頁數 - 1 )X 每頁條數 , 每頁條數

Select * from table limit ($Page- 1) * $PageSize, $PageSize

3、$_SERVER["REQUEST_URI"]函數
預定義伺服器變數的一種,所有$_SERVER開頭的都叫做預定於伺服器變數。
REQUEST_URI的作用是取得當前URI,也就除域名外後面的完整的地址路徑。
例子:
當前頁為:http://www.test.com/home.php?id=23&cid=22
echo $_SERVER["REQUEST_URI"]
結果為:/home.php?id=23&cid=22
4、parse_url()解析URL函數
parse_url() 是講URL解析成有固定鍵值的數組的函數
例子

$ua=parse_url("http://username:password@hostname/path?arg=value#anchor");
print_r($ua);

結果:

Array
(
[scheme] => http ;協議
[host] => hostname ;主機域名
[user] => username ;用戶
[pass] => password ;密碼
[path] => /path ;路徑
[query] => arg=value ;取參數
[fragment] => anchor ;
)

5、代碼實例
這個一個留言的分頁,分為3個部分,一個是資料庫設計,一個是連接頁面,一個是顯示頁面。
(1)設計資料庫
設計資料庫名為bbs,有一個數據表為message,裡麵包含title,lastdate,user,content等欄位,分別表示留言標題,留言日前,留言人,留言的內容
(2)連接頁面

<?php
$conn = @ mysql_connect("localhost", "root", "123456") or die("資料庫鏈接錯誤");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); //使用GBK中文編碼;
//將空格,換行轉換為HTML可解析
function htmtocode($content) {
$content = str_replace("\n", "<br>", str_replace(" ", " ", $content)); //兩個str_replace嵌套
return $content;
}
//$content=str_replace("'","『",$content);
//htmlspecialchars();

?>

(3)顯示頁面

<?php
include("conn.php");
$pagesize=2; //設置每頁顯示2個記錄
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url[path];

$numq=mysql_query("SELECT * FROM `message`");
$num = mysql_num_rows($numq);
if($_GET){
$pageval=$_GET;
$page=($pageval-1)*$pagesize;
$page.=',';
}
if($num > $pagesize){
if($pageval<=1)$pageval=1;
echo "共 $num 條".
" <a href=$url?page=".($pageval-1).">上一頁</a> <a href=$url?page=".($pageval+1).">下一頁</a>";
}
$SQL="SELECT * FROM `message` limit $page $pagesize ";
$query=mysql_query($SQL);

while($row=mysql_fetch_array($query)){
?>
<table width=500 border="0" cellpadding="5" cellspacing="1" bgcolor="#add3ef">
<tr bgcolor="#eff3ff">
<td>標題:<?php echo $row[title]?></td> <td>時間:<?php echo $row[lastdate]?></td>
</tr>
<tr bgcolor="#eff3ff">
<td> 用戶:<?php echo $row[user]?></td><td></td>
</tr>
<tr>
<td>內容:<?php echo htmtocode($row[content]);?></td>
</tr>
<br>
</table>
<?php
}
?>

方法3:
<script>
function viewpage(p){
if(window.XMLHttpRequest){
var xmlReq = new XMLHttpRequest();
} else if(window.ActiveXObject) {
var xmlReq = new ActiveXObject('Microsoft.XMLHTTP');
}
var formData = "page="+p;
xmlReq.onreadystatechange = function(){
if(xmlReq.readyState == 4){
document.getElementByIdx_x('content2').innerHTML = xmlReq.responseText;
}
}
xmlReq.open("post", "hotel_list.php", true);
xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlReq.send(formData);
return false;
}
</script>

腳本2:

header("Content-Type:text/html;charset=GB2312");
$pagesize=10;
//echo $_POST['page'];
$result = mysql_query("Select count(DISTINCT hotelname) FROM ".TBL_HOTELS);
$myrow = mysql_fetch_array($result);
$numrows=$myrow[0];

$pages=intval($numrows/$pagesize);
if ($numrows%$pagesize)
$pages++;
if (isset($_POST['page'])){
$page=intval($_POST['page']);
}
else{
//設置為第一頁
$page=1;
}
$first=1;
$prev=$page-1;
$next=$page+1;
$last=$pages;
//計算記錄偏移量
$offset=$pagesize*($page - 1);
//讀取指定記錄數
$result=mysql_query("select `hotelname` , count( * ) from ".TBL_HOTELS." GROUP BY `hotelname` order by id desc limit $offset,$pagesize");
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
$hotelname[] = $row[0];
$countpeople[] = $row[1];
}
for($a=0;$a<$num;$a++)
{
//$result=mysql_query("select count(title) from " . TBL_Comments ." where `title`=\"".$title[$a]."\"");
//$row = mysql_fetch_row($result);
echo "<TABLE style=\"MARGIN-BOTTOM: 20px\" cellSpacing=0 cellPadding=0 width=100% border=0>\n";
echo "<TBODY>\n";
echo "<TR>\n";
echo "<TD style=\"PADDING-TOP: 5px\" vAlign=top align=left width=80>\n";
//rating_bar($title[$a],5);
echo "</TD>\n";
echo "<TD style=\"PADDING-TOP: 5px\" align=left width=100%><A title=$hotelname[$a] style=\"FONT-SIZE: 14px\" href=#>$hotelname[$a]</A>\n";
echo "</TD></TR>\n";
echo " <TR>\n";
echo "<TD></TD>\n";
echo "<TD style=\"PADDING-LEFT: 0px\">\n";
echo "<IMG src=\"images/comment.gif\" border=0> 推薦人數:($countpeople[$a]) |\n";
echo "<SPAN>平均分:<STRONG></STRONG> (".$count."票) | 評論數:()</SPAN>\n";
echo "</TD></TR></TBODY></TABLE>\n";
}
echo "<TABLE style=\"MARGIN-TOP: 30px\" cellSpacing=0 cellPadding=0 width=\"100%\"";
echo "border=0>";
echo "<TBODY><TR><TD colSpan=3 height=20>";
echo "<DIV align=center>";
echo "<P align=left><FONT color=red>第".$page."頁/總".$pages."頁 | 總".$numrows."條</FONT> | ";
if ($page>1) echo "<a onclick=\"viewpage(".$first.")\" href='#'>首頁</a> | ";
if ($page>1) echo "<a onclick=\"viewpage(".$prev.")\" href='#'>上頁</a> | ";
if ($page<$pages) echo "<a onclick=\"viewpage(".$next.")\" href='#'>下頁</a> | ";
if ($page<$pages) echo "<a onclick=\"viewpage(".$last.")\" href='#'>尾頁</a>";
echo "轉到第 <INPUT maxLength=3 size=3 value=1 name=goto_page> 頁 <INPUT hideFocus onclick=\"viewpage(document.all.goto_page.value)\" type=button value=Go name=cmd_goto>";
echo "</P></DIV></TD></TR></TBODY></TABLE>";

㈣ php做條件查詢時的分頁傳值問題

你這程序做得真不錯,但是還是亂啊,我測試都沒辦法測試。提出個問題: $sel=$_POST['select'];
$sel2=$_POST['select2'];
你這樣接收了兩個變數,你這兩個變數在每次刷新頁數輸出查詢結果時,到底如何傳遞的 ?我發現你根本沒有傳遞這兩個變數;你測試下: $sel=$_POST['select'];
$sel2=$_POST['select2'];echo '<br/>$sel'.$sel.'<br/>';echo '$sel2'.$sel2.'<br/>'; 建議:一開始使用post,已經輸入後使用get,該select與select2通過html傳輸。再則,你的查詢條件:年代,類別。(我不知道這兩個是不是查詢條件,看不出來。。。。)是如何輸入的?等你說明下你到底想實現什麼樣的功能再貼上來吧哥哥。。。。。我幫你改了下,不知道能不能運行,自己測試下吧: <?php

include("conn.php");

if(isset($_POST['select']))//這里修改下
$sel=$_POST['select'];//這里修改下
else//這里修改下
$sel = $_GET['select'];//這里修改下
if(isset($_POST['select2']))//這里修改下
$sel2=$_POST['select2'];//這里修改下
else//這里修改下
$sel2 = $_GET['select2'];//這里修改下
if($sel=='' and $sel2=='')//這里修改下
$sql="select * from test";//這里修改下
elseif($sel!='' and $sel2=='')//這里修改下
$sql="select * from test where leibie like '%$sel%'";
elseif($sel=='' and $sel2!='')//這里修改下
$sql="select * from test where niandai like '%$sel2%'";
else
$sql="select * from test where leibie like '%$sel%' and niandai like '%$sel2%' ";
$result=mysql_query($sql);
$total=mysql_num_rows($result);
include("pageft.php");
pageft($total,10);
$info=mysql_query("$sql limit $firstcount,$displaypg");
if(!$info)
echo '<font size=6 color=red ><p align="center">沒有您所要查找的內容,請重新查找!</p></font>';

?> <table width="655" height="40" border="0" align="center">
<tr>
<td width="680" align="right"><span class="STYLE5 STYLE7"><?php if($info) echo $pagenav;?>
</span></td>
</tr>
</table>
<table width="847" height="48" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr>
<td width="86" align="center"><span class="STYLE1 STYLE8">名稱</span></td>
<td width="85" align="center"><span class="STYLE1 STYLE9">年代</span></td>
<td width="83" align="center"><span class="STYLE1 STYLE8">類別</span></td>
<td width="495" align="center"><span class="STYLE1 STYLE13 STYLE11">文物簡介</span></td>
<td width="86" align="center"><span class="STYLE1 STYLE11 STYLE13">圖片</span></td>
</tr>
</table>
<?php
if($info)
while($row=mysql_fetch_array($info)){
$m=$m+1;
?>
<table width="844" height="51" border="1" align="center" cellspacing="0">
<tr>
<td width="86" align="center"><?php echo $m,"-",$row[name_db];?></td>
<td width="83" align="center"><?php echo $row[niandai];?></td>
<td width="81" align="center"><?php echo $row[leibie];?></td>
<td width="502" align="left"><?php echo $row[remark];?></td>
<td width="80" align="center"><a href="../images/<?php echo $row[image_db];?> "target="_blank"><img src="../images/<?php echo $row [image_db];?>"width='80' height='80' /></td>
</tr>
</table>
<?php } ; ?>
<table width="838" height="75" border="0" align="center">
<tr>
<td width="824" align="center" class="STYLE5 STYLE7"> <?php if($info) echo $pagenav;?></td>
</tr>
</table></body>
</html>
下面的是分頁代碼<?php
//為了避免重復包含文件而造成錯誤,加了判斷函數是否存在的條件:
if(!function_exists(pageft)){
//定義函數pageft(),三個參數的含義為:
//$totle:信息總數;
//$displaypg:每頁顯示信息數
//$url:分頁導航中的鏈接,除了加入不同的查詢信息「page」外的部分都與這個URL相同。
//默認值本該設為本頁URL(即$_SERVER["REQUEST_URI"]),但設置默認值的右邊只能為常量,所以該默認值設為空字元串,在函數內部再設置為本頁URL。
function pageft($totle,$displaypg=10,$url=''){//定義幾個全局變數:
//$page:當前頁碼;
//$firstcount:(資料庫)查詢的起始項;
//$pagenav:頁面導航條代碼,函數內部並沒有將它輸出;
//$_SERVER:讀取本頁URL「$_SERVER["REQUEST_URI"]」所必須。
global $m,$page,$firstcount,$pagenav,$_SERVER;//為使函數外部可以訪問這里的「$displaypg」,將它也設為全局變數。注意一個變數重新定義為全局變數後,原值被覆蓋,所以這里給它重新賦值。
$GLOBALS["displaypg"]=$displaypg;if(!$page) $page=1;
//如果$url使用默認,即空值,則賦值為本頁URL:
if(!$url){ $url=$_SERVER["REQUEST_URI"];}
//URL分析:
$parse_url=parse_url($url);
$url_query=$parse_url["query"]; //單獨取出URL的查詢字串
if($url_query){
//因為URL中可能包含了頁碼信息,我們要把它去掉,以便加入新的頁碼信息。
//這里用到了正則表達式
$url_query=ereg_replace("(^|&)page=$page","",$url_query);//將處理後的URL的查詢字串替換原來的URL的查詢字串:
$url=str_replace($parse_url["query"],$url_query,$url);//在URL後加page查詢信息,但待賦值:
if($url_query)
$url.="&page"; else $url.="page";
}else {
$url.="?page";
}
$lastpg=ceil($totle/$displaypg); //最後頁,也是總頁數
$page=min($lastpg,$page);
$prepg=$page-1; //上一頁
$nextpg=($page==$lastpg ? 0 : $page+1); //下一頁$firstcount=($page-1)*$displaypg;//開始分頁導航條代碼:
$m=$firstcount;
$pagenav="顯示第 <b>".($totle?($firstcount+1):0)."</b>-<b>".min($firstcount+$displaypg,$totle)."</b> 條記錄,
共 $totle 條記錄<br>";//如果只有一頁則跳出函數:
if($lastpg<=1) return false;
echo '<br/>$url'.$url.'<br/>';
if($prepg) $pagenav.=" <a href='$url=1&select=$sel&select2=$sel2'>首頁</a> "; else $pagenav.="首頁 ";//這里修改下
if($prepg) $pagenav.=" <a href='$url=$prepg&select=$sel&select2=$sel2'>上一頁</a> "; else $pagenav.="上一頁 ";//這里修改下
if($nextpg) $pagenav.=" <a href='$url=$nextpg&select=$sel&select2=$sel2'>下一頁</a> "; else $pagenav.="下一頁 ";//這里修改下
if($nextpg) $pagenav.=" <a href='$url=$lastpg&select=$sel&select2=$sel2'>末頁</a> "; else $pagenav.="末頁 ";//這里修改下//下拉跳轉列表,循環列出所有頁碼:
$pagenav.="轉<select name='topage' size='1' onchange='window.location=\"$url=\"+this.value&select=$sel&select2=$sel2'>\n";//這里修改下
for($i=1;$i<=$lastpg;$i++){
if($i==$page) $pagenav.="<option value='$i' selected>$i</option>\n";
else $pagenav.="<option value='$i'>$i</option>\n";
}
$pagenav.="</select> 頁,共 $lastpg 頁";
}
}
?>

㈤ PHP 查詢結果分頁顯示

信息太少 只能寫下面一部分
將while裡面改一下即可
<?php
$page_size=20;//每頁信息條數
//解析URL
$url=$_SERVER["REQUEST_URL"];
$url=parse_url($url);
$url=$url[path];

$numq=mysql_query("SELECT * FROM `表名`");
$num=mysql_num_rows($numq);
$page_first=1;
$page_last=ceil($num/$page_size);//獲得總頁數 也就是最後一頁的數值

if ($_GET[page]>=1){
$page_num=$_GET[page];
$page_nums=($page_num-1)*$page_size;
}else{
$page_num=1;
$page_nums=($page_num-1)*$page_size;
}
echo $num."條記錄,共".$page_last."頁"."====<b><big>這是第".$page_num."頁</big></b>"."<br>";

for($i=1;$i<=$page_last;$i++){
echo "<a href=$url2?page=".($page_num+$i-1).">"."第".($page_num+$i-1)."頁>> "."</a>";
}
$sql="SELECT * FROM `表名` limit $page_nums,$page_size";
$query=mysql_query($sql);
echo "<table border=1><tr ><th>姓名</th><th>姓別</th></tr>";

while($row=mysql_fetch_array($query)){
echo "<tr ><td>";
echo $row[name];
echo "</td>";
echo "<td>";
echo $row[sex];
echo "</td></tr>";
}

echo "</table>";
?>

㈥ 關於php多條件模糊查詢後分頁問題!

<?php
define('IN_JOBS', true);
require_once("./cc_include/common.php");
require_once("./cc_include/page.class.php");
require_once("./cc_include/page_function.php");

require_once("./cc_include/Site_Config.php");

//載入smarty模板
$smarty = new Smarty();
$smarty->template_dir="./templates/default/";
$smarty->compile_dir="./templates_c/default/";
$smarty->cache_dir=CACHE_PATH;
$smarty->left_delimiter="{*";
$smarty->right_delimiter="*}";
$smarty->caching=false;
//開始跑首頁信息
$Gonggao=News(1, 5);
//以上信息為公告和右側的兩個新聞

if (isset($_GET['sousuo'])) $searchname = $_GET['sousuo'];//得到搜索關鍵詞
else if (isset($_POST['sousuo'])) $searchname = $_POST['sousuo'];

if(!isset($searchname))
{
echo "<script>location.href='index.php';</script>";
}
$typename=$_POST['type'];
$shijian=$_POST['rboname'];
$xitongshijian=date("Y-m-d");//獲得系統當前時間
$jianyitian=date('Y-m-d H:i:s',strtotime("$a-1 day"));//減去一天時間

$jiansantian=date('Y-m-d',strtotime("$a-3 day"));//減去三天時間

$jianqitian=date('Y-m-d',strtotime("$a-7 day"));//減去7天時間

switch($typename)
{
case "職位名":
if($shijian=="")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' order by Adddate desc";

}
else if($shijian=="近一天")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jianyitian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近三天")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jiansantian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近一星期")
{
$tiaojian="Shenhe=1 and Gzxx like '%".$searchname."%' and Adddate between '".$jianqitian."' and '".$xitongshijian."' order by Adddate desc";
}
break;
case "工作時間":
if($shijian=="")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' order by Adddate desc";
}
else if($shijian=="近一天")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jianyitian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近三天")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jiansantian."' and '".$xitongshijian."' order by Adddate desc";
}
else if($shijian=="近一星期")
{
$tiaojian="Shenhe=1 and Gzsj like '%".$searchname."%' and Adddate between '".$jianqitian."' and '".$xitongshijian."' order by Adddate desc";
}
break;
}

$perNumber=5; //每頁顯示的記錄數
$page=$_GET['page']; //獲得當前的頁面值
$count=mysql_query("select count(*) from ejz_wor where ".$tiaojian.""); //獲得記錄總數

$rs=mysql_fetch_array($count);
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); //計算出總頁數
if (!isset($page)) {
$page=1;
} //如果沒有值,則賦值1
$startCount=($page-1)*$perNumber; //分頁開始,根據此方法計算出開始的記錄
$sql="select Wor_id,Gzxx,Zprs,Gzsj,Gzyq,Daiyu,Adddate,jipin from ejz_wor where ".$tiaojian." limit $startCount,$perNumber";
$result=mysql_query($sql);
while ($row=mysql_fetch_object($result))
{
?>
<ul>
<li><div class="kf_xian" align="left"><? echo "$row->Gzxx"?> <a href="#" style="text-align:left"><? echo "$row->Gzsj"?></a></div></li>
<li><? echo "$row->Daiyu"?></li>
<li>管理員回復:<? echo "$row->Adddate"?></li>
</ul>
<?
}
if ($page != 1) { //頁數不等於1
?>

<?php echo "總共".$totalPage."頁,";?>
<a href="wj.php?page=<?php echo $page - 1;?>&sousuo=<?php echo $searchname;?>">上一頁</a> <!--顯示上一頁-->
<?php
}
for ($i=1;$i<=$totalPage;$i++) { //循環顯示出頁面
?>
<a href="wj.php?page=<?php echo $i;?>&sousuo=<?php echo $searchname;?>"><?php echo $i ;?></a>
<?php
}
if ($page<$totalPage) { //如果page小於總頁數,顯示下一頁鏈接
?>
<a href="wj.php?page=<?php echo $page + 1;?>&sousuo=<?php echo $searchname;?>">下一頁</a>
<?php
}
?>

㈦ php 查詢結果分頁問題

最近剛學的PHP。。。

㈧ php mysql查詢結果分頁顯示

查詢語句加上 limit 12

熱點內容
樹莓派源碼 發布:2025-02-09 05:07:00 瀏覽:650
安卓手機為什麼搜不到懂球帝 發布:2025-02-09 05:04:42 瀏覽:817
生命密碼解讀走什麼 發布:2025-02-09 04:55:51 瀏覽:279
python常用正則表達式 發布:2025-02-09 04:42:53 瀏覽:178
機器人編程培訓哪家好 發布:2025-02-09 04:37:44 瀏覽:308
上海怎麼學習java 發布:2025-02-09 04:26:39 瀏覽:23
erp系統搭建備用伺服器 發布:2025-02-09 04:07:38 瀏覽:946
戴爾伺服器在bios怎麼配置管理ip 發布:2025-02-09 04:01:53 瀏覽:551
小魚易連雲存儲 發布:2025-02-09 03:59:47 瀏覽:92
正在限制訪問 發布:2025-02-09 03:47:17 瀏覽:904