[請益] 多條件搜尋下之分頁功能...
搜尋條件有多筆,是利用表單傳遞
而分頁功能是用url傳遞
查詢結果第一頁可以正常顯示,
但如果超過一頁,要按「下一頁」或「上一頁」,
就搜尋不到資料,
應該是變數傳遞的問題??
不知有什麼解決方法,試了好幾種都沒用...
以下是處理分頁的程式碼---
$maxRows_house_qry = 6;
$pageNum_house_qry = 0;
if (isset($_REQUEST['pageNum_house_qry'])) {
$pageNum_house_qry = $_REQUEST['pageNum_house_qry'];
}
$startRow_house_qry = $pageNum_house_qry * $maxRows_house_qry;
if (isset($_REQUEST['totalRows_house_qry'])) {
$totalRows_house_qry = $_REQUEST['totalRows_house_qry'];
} else {
$all_house_qry = mysql_query($sql);
$totalRows_house_qry = mysql_num_rows($all_house_qry);
}
$totalPages_house_qry = ceil($totalRows_house_qry/$maxRows_house_qry)-1;
---------------------------
(以下是分頁連結)
<?php if ($pageNum_house_qry > 0) {?>
<a href="<?php @printf("?pageNum_house_qry=%d", 0); ?>">第一頁 </a> <?php } ?>
<?php if ($pageNum_house_qry > 0) { ?>
<a href="<?php @printf("?pageNum_house_qry=%d", max(0,$pageNum_house_qry - 1)); ?>">▲ 上ㄧ頁 </a>
<?php } ?>
<?php if ($pageNum_house_qry < $totalPages_house_qry) { ?>
<a href="<?php @printf("?pageNum_house_qry=%d", min($totalPages_house_qry, $pageNum_house_qry + 1)); ?>">下一頁 ▼ </a>
<?php } ?>
<?php if ($pageNum_house_qry < $totalPages_house_qry) { ?>
<a href="<?php @printf("?pageNum_house_qry=%d", $totalPages_house_qry); ?>">最後頁</a>
<?php } ?>
<? echo "<br>(第".($pageNum_house_qry+1)."頁 共".($totalPages_house_qry+1)."頁)";?>
-----------------------------
(附上SQL敘述句)
$sql="select * from house_info where H_ID is not null ";
$sql_nums="";
if($_REQUEST['Style']!="請選擇"){
$sql.= " and Style = '".$_REQUEST['Style']."' ";
//$sql_nums.="Style='".$_REQUEST['Style']."' ";
}
if($_REQUEST['Area']!="請選擇"){
$sql.=" and Area = '".$_REQUEST['Area']."' ";
//$sql_nums.="& Area='".$_REQUEST['Area']."' ";
}
if($_REQUEST['Stall']!="請選擇"){
$sql.=" and Stall = '".$_REQUEST['Stall']."' ";
//$sql_nums.="& Stall='".$_REQUEST['Stall']."'";
}
if($_REQUEST['Addr']!=""){
$sql.=" and Addr like '%".stripslashes($_REQUEST['Addr'])."%' ";
//$sql_nums.="& Addr= '".$_REQUEST['Addr']."'";
}
if($_REQUEST['Room_start']!="" && $_REQUEST['Room_end']!=""){
$sql.=" and Room between ".stripslashes($_REQUEST['Room_start'])." and ".stripslashes($_REQUEST['Room_end'])." ";
//$sql_nums.="& Room_start= '".$_REQUEST['Room_start']."' & Room_end = '". $_REQUEST['Room_end']."'";
}
if($_REQUEST['Place_start']!="" && $_REQUEST['Place_end']!=""){
$sql.=" and Place between ".stripslashes($_REQUEST['Place_start'])." and ".stripslashes($_REQUEST['Place_end'])." ";
//$sql_nums.="& Place_start = '".$_REQUEST['Place_start']."' & Place_end = '".$_REQUEST['Place_end']."' ";
}
if($_REQUEST['Build_start']!="" && $_REQUEST['Build_end']!=""){
$sql.=" and Building between ".stripslashes($_REQUEST['Build_start'])." and ".stripslashes($_REQUEST['Build_end'])." ";
//$sql_nums.="& Build_start = '".$_REQUEST['Build_start']."' & Build_end = '".$_REQUEST['Build_end']."'";
}
if($_REQUEST['Price_start']!="" && $_REQUEST['Price_end']!=""){
$sql.=" and Price between ".stripslashes($_REQUEST['Price_start'])." and ".stripslashes($_REQUEST['Price_end'])." ";
//$sql_nums.="& Price_start = '".$_REQUEST['Price_start']."' & Price_end = '".$_REQUEST['Price_end'] ."'";
}
$totalPages_house_qry = ceil($totalRows_house_qry/$maxRows_house_qry)-1;
$sql_qry = sprintf(" %s LIMIT %d, %d",$sql , $startRow_house_qry, $maxRows_house_qry);
$house_qry = mysql_query($sql_qry, $link) or die(mysql_error());
//echo $sql;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.74.246
※ 編輯: sss5 來自: 114.40.74.246 (10/22 13:09)
※ 編輯: sss5 來自: 114.40.74.246 (10/22 13:19)
推
10/22 14:29, , 1F
10/22 14:29, 1F
→
10/22 16:20, , 2F
10/22 16:20, 2F
推
10/22 17:01, , 3F
10/22 17:01, 3F
→
10/22 17:01, , 4F
10/22 17:01, 4F
→
10/22 17:02, , 5F
10/22 17:02, 5F
→
10/22 17:06, , 6F
10/22 17:06, 6F
→
10/22 17:06, , 7F
10/22 17:06, 7F
→
10/22 17:08, , 8F
10/22 17:08, 8F
→
10/22 17:08, , 9F
10/22 17:08, 9F
※ 編輯: sss5 來自: 114.33.190.170 (10/22 17:41)
→
10/22 17:44, , 10F
10/22 17:44, 10F
推
10/22 18:18, , 11F
10/22 18:18, 11F
→
10/22 18:19, , 12F
10/22 18:19, 12F
→
10/22 18:19, , 13F
10/22 18:19, 13F
→
10/22 18:25, , 14F
10/22 18:25, 14F
→
10/22 18:25, , 15F
10/22 18:25, 15F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
3
15
PHP 近期熱門文章
PTT數位生活區 即時熱門文章