jQueryを使用し、PHPファイルに飛び配列を返すプログラムがあります。コードが機能することは確認済みなのですが、引数等を変更している間にどこかが狂ってしまいました。
PHP
1<?php 2ini_set('display_errors', 1); 3 4var_dump(1);//console.logにでない 5 6$reviews = array( 7 array('hotel_id' => '1', 'country_code'=>'PHL', 'title'=>'気に入りました', 'date'=>'2016/09/21', 'number'=>'8', 'word'=>'非常に満足', 'name'=>'Chandler', 'country'=>'JPN', 'text'=>'レビューが良かったので気になってたホテル。初めて泊まりましたが常宿決定。 新館に泊まりましたが、価格に対して部屋の広さ、設備が良い。周りに日本食屋が多い。隣りの焼肉屋がとても美味しかった。 ホテルのマッサージも良かった。 8 アヤラモールもタクシーですぐだし、銀行も徒歩圏内。旅行会社も並びにあるみたいで翌日のボホール島のチケットも買えるらしい。とにかく便利で部屋も満足。熱いシャワーも出る。'), 9 10 array('hotel_id' => '1','country_code'=>'PHL', 'title'=>'ロケーション良い', 'date'=>'2016/10/21', 'number'=>'9', 'word'=>'満足', 'name'=>'Chandler', 'country'=>'JPN', 'text'=>'レビューが良かったので気になってたホテル。初めて泊まりましたが常宿決定。 新館に泊まりましたが、価格に対して部屋の広さ、設備が良い。周りに日本食屋が多い。隣りの焼肉屋がとても美味しかった。 ホテルのマッサージも良かった。 11 アヤラモールもタクシーですぐだし、銀行も徒歩圏内。旅行会社も並びにあるみたいで翌日のボホール島のチケットも買えるらしい。とにかく便利で部屋も満足。熱いシャワーも出る。'), 12 13 array('hotel_id' => '1', 'country_code'=>'PHL','title'=>'セブでベスト', 'date'=>'2016/10/23', 'number'=>'8', 'word'=>'満足', 'name'=>'Chandler', 'country'=>'JPN', 'text'=>'この値段でこのクオリティは素晴らしい。広さを除けば、部屋のグレードはマルコポーロ・ホテルと遜色ありません。 14 立地もよく便利なホテルです。前面道路の騒音だけがマイナスポイント。おススメです。'), 15 16 array('hotel_id' => '1', 'country_code'=>'PHL','title'=>'good hotel', 'date'=>'2018/10/03', 'number'=>'8', 'word'=>'非常に満足', 'name'=>'Chandler', 'country'=>'PHL', 'text'=>'動きやすい場所にあり、知名度もありホテルに帰るのが楽。部屋はリノベーションされてて綺麗で居心地よい。 17 近くにあるタイのスパはオススメです。前回に続き二度目の利用ですが、次回もここかな。'), 18 19 array('hotel_id' => '1', 'country_code'=>'PHL','title'=>'評判通りの良いホテル”', 'date'=>'2019/01/03', 'number'=>'8', 'word'=>'満足', 'name'=>'Chandler', 'country'=>'JPN', 'text'=>'評判通りの良いホテル'), 20 21 array('hotel_id' => '1', 'country_code'=>'PHL','title'=>'良いホテル”', 'date'=>'2016/01/23', 'number'=>'8', 'word'=>'非常に満足', 'name'=>'Chandler', 'country'=>'JPN', 'text'=>'また行きたいと思います'), 22 23 array('hotel_id' => '1','country_code'=>'PHL', 'title'=>'便利なロケーション', 'date'=>'2017/08/07', 'number'=>'8', 'word'=>'非常に満足', 'name'=>'Chandler', 'country'=>'JPN', 'text'=>'セブに滞在の際利用しますが、交通の利便性、立地環境などがいいとおもいます。 24 価格に対するパフォーマンスもgood!です。') 25); 26 27 28function getReviews($limitation, $cpage, $hotelid, $countrycode) 29{ 30 if (isset($limitation, $cpage, $hotelid, $countrycode)) { 31 global $reviews; 32 $results = array();//返す配列 33 $selectedreviews = array();//国コードとホテルidで選ばれたreviews 34 foreach ($reviews as $review) { 35 if ($review['hotel_id'] == $hotelid && $review['country_code'] == $countrycode) { 36 $selectedreviews[] = $review; 37 } 38 } 39 40 $i = ($cpage * $limitation) - $limitation; 41 $k = $i + $limitation; 42 for ($i; $i < $k ; $i++) { 43 if (isset($selectedreviews[$i])) { 44 $results[] = $selectedreviews[$i]; 45 } 46 } 47 if (count($results) == 0) { 48 return 0; 49 } 50 return $results; 51 } 52} 53 54var_dump(getReviews(5, 1, 1, 'PHL')); 55var_dump(getMaxpage(1, 'PHL')); 56 57 58function getMaxpage($hotelid, $countrycode) 59{ 60 if (isset($hotelid, $countrycode)) { 61 global $reviews; 62 $selectedreviews = array(); 63 foreach ($reviews as $review) { 64 if (($review['hotel_id'] == $hotelid) && ($review['country_code'] == $countrycode)) { 65 $selectedreviews[] = $review; 66 } 67 } 68 return count($selectedreviews); 69 } 70} 71 72if ($_SERVER['REQUEST_METHOD'] === 'POST') { 73 if (isset($_POST['cpage'],$_POST['limitation'],$_POST['hotelid'],$_POST['countrycode'])) { 74 $limitation = $_POST['limitation']; 75 $cpage = $_POST['cpage']; 76 $hotelid = $_POST['hotelid']; 77 $countrycode = $_POST['countrycode']; 78 header('Content-Type: application/json'); 79 echo json_encode(getReviews($limitation, $cpage, $hotelid, $countrycode)); 80 exit; 81 } 82} 83 84if ($_SERVER['REQUEST_METHOD'] === 'POST') { 85 if (isset($_POST['function'],$_POST['hotelid'],$_POST['countrycode']) && $_POST['function'] == 'getMaxpage') { 86 header('Content-Type: application/json'); 87 $hotelid = $_POST['hotelid']; 88 $countrycode = $_POST['countrycode']; 89 $maxpage = getMaxpage($hotelid, $countrycode); 90 echo json_encode([ 91 'maxpage' => $maxpage 92 ]); 93 exit; 94 } 95}
これがajax空の遷移先のPHPです。最上部付近にあるvar_dump(1)が表示されません。どこまでプログラムが進んでいるか分からず困っています。
よろしくお願いします。またPHPのエラーログも更新されていないです。
ちなみにメソッド機能は確認済みなので、動く方のPHPを貼ります。
PHP
1if ($_SERVER['REQUEST_METHOD'] === 'POST') { 2 if (isset($_POST['hotelid'],$_POST['action'],$_POST['countrycode']) && $_POST['action'] == 'plus') { 3 try { 4 $hotelid = $_POST['hotelid']; 5 $action = $_POST['action']; 6 $countrycode = $_POST['countrycode']; 7 $dtabase->updateLikes($hotelid, $countrycode, $action); 8 $reslut = $dtabase->getLikes($hotelid, $countrycode); 9 header('Content-Type: application/json'); 10 echo json_encode($reslut); 11 } catch (PDOException $e) { 12 return false; 13 } 14 exit; 15 } elseif (isset($_POST['hotelid'],$_POST['action'],$_POST['countrycode']) && $_POST['action'] == 'minus') { 16 try { 17 $hotelid = $_POST['hotelid']; 18 $action = $_POST['action']; 19 $countrycode = $_POST['countrycode']; 20 $dtabase->updateLikes($hotelid, $countrycode, $action); 21 $reslut = $dtabase->getLikes($hotelid, $countrycode); 22 header('Content-Type: application/json'); 23 echo json_encode($reslut); 24 } catch (PDOException $e) { 25 return false; 26 } 27 exit; 28 } elseif (isset($_POST['hotelid'],$_POST['action'],$_POST['countrycode']) && $_POST['action'] == 'get') { 29 try { 30 $hotelid = $_POST['hotelid']; 31 $countrycode = $_POST['countrycode']; 32 $reslut = $dtabase->getLikes($hotelid, $countrycode); 33 header('Content-Type: application/json'); 34 echo json_encode($reslut); 35 } catch (PDOException $e) { 36 return false; 37 } 38 exit; 39 } 40}
こちらもAjaxからの処理です。
回答2件
あなたの回答
tips
プレビュー