Re: [請益] 多條件搜尋下之分頁功能...
我重新改寫了一下...
變成以下的程式碼
如果個別印出每個變數就可以知道出什麼問題
會有參數帶不到下一頁去
例如.....
select * from house_info where H_ID is not null
and Style = '套房' limit 0,6 n:3num:6page:1total:18
(這是原始頁)
-----------
(按下「下一頁」後)
select * from house_info where H_ID is not null
and Style = '' and Area = '' and Stall = '' limit 6,6 n:0num:6page:2total:0
---------------
只要是總頁數跟總筆數跑掉...
有什麼方式可以讓變數一直存在於查詢的網頁中???
(程式碼)
----------------
$page=(empty($_REQUEST['page']))?1:$_REQUEST['page'];
$num=6;
$total=0;
$start=($page-1)*$num;
$sql="select * from house_info where H_ID is not null ";
$sql_count="select count(*) from house_info where H_ID is not null ";
$sql_nums="";
if($_REQUEST['Style']!="隢鹉坥蜢){
$sql.= " and Style = '".$_REQUEST['Style']."' ";
$sql_count.=" and Style = '".$_REQUEST['Style']."' ";
}
if($_REQUEST['Area']!="隢鹉坥蜢){
$sql.=" and Area = '".$_REQUEST['Area']."' ";
$sql_count.=" and Area = '".$_REQUEST['Area']."' ";
}
if($_REQUEST['Stall']!="隢鹉坥蜢){
$sql.=" and Stall = '".$_REQUEST['Stall']."' ";
$sql_count.=" and Stall = '".$_REQUEST['Stall']."' ";
}
if($_REQUEST['Addr']!=""){
$sql.=" and Addr like '%".stripslashes($_REQUEST['Addr'])."%' ";
$sql_count.=" and Addr like '%".stripslashes($_REQUEST['Addr'])."%' ";
}
if($_REQUEST['Room_start']!="" && $_REQUEST['Room_end']!=""){
$sql.=" and Room between ".stripslashes($_REQUEST['Room_start'])." and ".stripslashes($_REQUEST['Room_end'])." ";
$sql_count.=" and Room between ".stripslashes($_REQUEST['Room_start'])." and ".stripslashes($_REQUEST['Room_end'])." ";
}
if($_REQUEST['Place_start']!="" && $_REQUEST['Place_end']!=""){
$sql.=" and Place between ".stripslashes($_REQUEST['Place_start'])." and ".stripslashes($_REQUEST['Place_end'])." ";
$sql_count.=" and Place between ".stripslashes($_REQUEST['Place_start'])." and ".stripslashes($_REQUEST['Place_end'])." ";
}
if($_REQUEST['Build_start']!="" && $_REQUEST['Build_end']!=""){
$sql.=" and Building between ".stripslashes($_REQUEST['Build_start'])." and ".stripslashes($_REQUEST['Build_end'])." ";
$sql_count.=" and Building between ".stripslashes($_REQUEST['Build_start'])." and ".stripslashes($_REQUEST['Build_end'])." ";
}
if($_REQUEST['Price_start']!="" && $_REQUEST['Price_end']!=""){
$sql.=" and Price between ".stripslashes($_REQUEST['Price_start'])." and ".stripslashes($_REQUEST['Price_end'])." ";
$sql_count.=" and Price between ".stripslashes($_REQUEST['Price_start'])." and ".stripslashes($_REQUEST['Price_end'])." ";
}
$result_1=mysql_db_query("home",$sql_count,$link) or die("⊥뎕綨뺗蝮質뎇⒡㕑嚗脼br>".$sql);
list($total) = mysql_fetch_row($result_1);
$limit="limit $start,$num";
$n=ceil($total/$num);
$sql.=" $limit ";
$next_page=$page+1;
$previous_page=$page-1;
$result2=mysql_db_query("home",$sql,$link) or die("⊥뎕綨뺗鞈欧隙嚗脼br>".$sql);
echo $sql;
echo "n:".$n."num:".$num."page:".$page."total:".$total;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.70.177
推
10/24 09:52, , 1F
10/24 09:52, 1F
→
10/24 09:53, , 2F
10/24 09:53, 2F
→
10/24 09:54, , 3F
10/24 09:54, 3F
→
10/24 09:54, , 4F
10/24 09:54, 4F
→
10/24 16:48, , 5F
10/24 16:48, 5F
→
10/24 16:49, , 6F
10/24 16:49, 6F
推
10/24 16:50, , 7F
10/24 16:50, 7F
→
10/24 16:55, , 8F
10/24 16:55, 8F
→
10/24 16:57, , 9F
10/24 16:57, 9F
→
10/24 17:04, , 10F
10/24 17:04, 10F
→
10/24 17:30, , 11F
10/24 17:30, 11F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
3
15
PHP 近期熱門文章
PTT數位生活區 即時熱門文章