お世話になります。
レシピサイトを作成しているのですが一覧表示でページネーションがうまくできなくて困っています。
2頁目をクリックすると「Forbidden access」になります。
前後の関係から少し長く記載していますが 対象部分は最下部の30行くらいだと思います。
検索からデータ抽出は120件ほどできています。
ご多忙のところ大変恐縮ですが、ご指導くださいませ。
発生している問題・エラーメッセージ
2頁目のリンクは
http://www.****.com/cook_ichiran.php?n=20&where= where meat_kbn=1 and ( meat_bui=1 or meat_bui=2)
となっていまして「Forbidden access」になります。
該当のソースコード
<?PHP require("../../inc/scp.php"); require("../../inc/config.php"); $db = pg_connect(DB_CONN) or die("接続失敗\n"); $err = ""; $n = (isset($_REQUEST["n"])) ? $_REQUEST["n"] : 0; $n2 = $n + 20; $where = ""; $where = (isset($_REQUEST["where"])) ? $_REQUEST["where"] : ""; if(strlen($_POST["search"]) > 0){ if(count($_POST["gyu"]) > 0){ $gyudata=""; for($i=0;$i<count($_POST["gyu"]);$i++){ if($i== 0){ $gyudata .= " meat_bui=".$_POST["gyu"][$i]; }else{ $gyudata .= " or meat_bui=".$_POST["gyu"][$i]; } } $where .= " where meat_kbn=1 and (".$gyudata.")"; } if(count($_POST["buta"]) > 0){ $butadata=""; for($i=0;$i<count($_POST["buta"]);$i++){ if($i==0){ $butadata .= "meat_bui=".$_POST["buta"][$i]; }else{ $butadata .= " or meat_bui=".$_POST["buta"][$i]; } } if(strlen($where) > 0){ $where .= " or meat_kbn=2 and (".$butadata.")"; }else{ $where .= " where meat_kbn=2 and (".$butadata.")"; } } }elseif(strlen($_POST["search2"]) > 0){ if(strlen($_POST['Zairyo_1']) > 0){ $recipe_cd = Nmae_val ('dbo_ht_recipezairyo_table','recipe_cd',' where zairyo_cd='.$_POST['Zairyo_1']); if(strlen($where) > 0){$where .= ' '.$_POST['WHEREVAL'].' recipe_cd='.$recipe_cd;}else{$where .= ' where recipe_cd='.$recipe_cd;} } if(strlen($_POST['Zairyo_2']) > 0){ $recipe_cd = Nmae_val ('dbo_ht_recipezairyo_table','recipe_cd',' where zairyo_cd='.$_POST['Zairyo_2']); if(strlen($where) > 0){$where .= ' '.$_POST['WHEREVAL'].' recipe_cd='.$recipe_cd;}else{$where .= ' where recipe_cd='.$recipe_cd;} } if(strlen($_POST['Zairyo_3']) > 0){ $recipe_cd = Nmae_val ('dbo_ht_recipezairyo_table','recipe_cd',' where zairyo_cd='.$_POST['Zairyo_3']); if(strlen($where) > 0){$where .= ' '.$_POST['WHEREVAL'].' recipe_cd='.$recipe_cd;}else{$where .= ' where recipe_cd='.$recipe_cd;} } if(strlen($_POST['zkw']) > 0){ $rstZ = pg_query($db,"select zairyo_cd from dbo_hm_zairyo_table where zairyo_name LIKE '%".$_POST['zkw']."%'"); if($rstZ){ while($colZ = pg_fetch_array($rstZ)){ $recipe_cd = Nmae_val ('dbo_ht_recipezairyo_table','recipe_cd',' where zairyo_cd='.$colZ[0]); if(strlen($where) > 0){$where .= ' '.$_POST['WHEREVAL'].' recipe_cd='.$recipe_cd;}else{$where .= ' where recipe_cd='.$recipe_cd;} } } } if(count($_POST['season_val']) > 0){ $seasondata=''; for($i=0;$i<count($_POST['season_val']);$i++){ if($i==0){ $seasondata .= 'season='.$_POST['season_val'][$i]; }else{ $seasondata .= ' or season='.$_POST['season_val'][$i]; } } if(strlen($where) > 0){ $where .= ' and ('.$seasondata.')'; }else{ $where .= ' where '.$seasondata; } } if(strlen($_POST['cook_time']) > 0){ if(strlen($where) > 0){ $where .= ' and cook_time <='.$_POST['cook_time']; }else{ $where .= ' where cook_time <='.$_POST['cook_time']; } } if(strlen($_POST['cook_class']) > 0){ if(strlen($where) > 0){ $where .= ' and cook_class <='.$_POST['cook_class']; }else{ $where .= ' where cook_class <='.$_POST['cook_class']; } } } //print $where."<br>"; $sql = "select * from dbo_ht_recipe_table ".$where." order by meat_kbn,meat_bui"; //print $sql; $rst = pg_query($db,$sql); if($rst){ while($col = pg_fetch_array($rst)){ $data[] = array($col[0],$col[1],$col[2],$col[31],$col[3],$col[4]); } } $cnt = count($data); if($cnt > ($n+20)){ $NEXTLINK .= "<a href='cook_ichiran.php?n=".($n+20)."&where=".$where."'>次20件 »</a>"; }else{ $NEXTLINK = ""; } if($n != 0){ $FRONTLINK .= "<a href='cook_ichiran.php?n=".($n-20)."&where=".$where."'>« 前20件</a>"; }else{ $FRONTLINK = ""; } $totalpage = ceil($cnt / 20); $page_main = $n2 / 20; for($i=1;$i<$totalpage+1;$i++){ if($page_main <> $i ) { $PLINK .= "<a href='cook_ichiran.php?n=".(($i-1)*20)."&where=".$where."'>".$i."</a> "; }else{ $PLINK .= $i." "; } } if($cnt >= $n2){$n3=$n2;}else{$n3=$cnt;} $buiarray = array("","牛","豚","鶏","その他"); ?>▼<!-- 頁移動ボタンの表示 HTML 部分 -->
<div> <?=$FRONTLINK ?> <?=$PLINK ?> <?=$NEXTLINK ?> </div>試したこと
20&where= where meat_kbn=1 and ( meat_bui=1 or meat_bui=2) のところを色々と変更してみました。
補足情報(FW/ツールのバージョンなど)
PostgreSQL8.4 php5.6 です。 phpPgAdminで操作しています。
回答1件
あなたの回答
tips
プレビュー