Re: [請益] 多條件搜尋下之分頁功能...

看板PHP作者 (屁)時間16年前 (2009/10/24 04:31), 編輯推噓2(209)
留言11則, 3人參與, 最新討論串2/2 (看更多)
我重新改寫了一下... 變成以下的程式碼 如果個別印出每個變數就可以知道出什麼問題 會有參數帶不到下一頁去 例如..... 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
要將變數存起來,可參照上一篇的推文我有提到的session.關於
10/24 09:52, 1F

10/24 09:53, , 2F
session的觀念及使用方式,上google打關鍵字就能夠找到一堆,
10/24 09:53, 2F

10/24 09:54, , 3F
使要更深入的說明,可上php官網查.要啟用php的session功能,可
10/24 09:54, 3F

10/24 09:54, , 4F
透過session_start() 函式.
10/24 09:54, 4F

10/24 16:48, , 5F
我試了,session也有接收到變數,但一樣的按下分頁後就接收不
10/24 16:48, 5F

10/24 16:49, , 6F
到,有利用SID傳送,但結果還是一樣
10/24 16:49, 6F

10/24 16:50, , 7F
沒start吧?
10/24 16:50, 7F

10/24 16:55, , 8F
用$_GET方式沒辦法達成嗎?為何只有某些變數值會跑掉?某些不會
10/24 16:55, 8F

10/24 16:57, , 9F
不清楚你GET的狀況,有可能是重複了,你可以dump出來看看
10/24 16:57, 9F

10/24 17:04, , 10F
有start,用簡單的方式ok,我先再想一下,謝謝
10/24 17:04, 10F

10/24 17:30, , 11F
解決了..原來是sql述敘句的問題,沒多判斷空值!
10/24 17:30, 11F
文章代碼(AID): #1AuXAI_X (PHP)
文章代碼(AID): #1AuXAI_X (PHP)