別スレのカウント処理について参考にやってみましたが、別問題に突き当たり解決方法が思い当たらないので再度失礼します。
https://teratail.com/questions/119574
※適切な題名が思いつかなかったのでGETのstr_replace変換についてにしています。
前提・実現したいこと
以下の発生している問題で+1追加ボタンをクリックすると①を挟まず、いきなりそのまま②に移りたい。
ボタンを押したら①→②ではなく
ボタンを押したらいきなり②といった形です。
発生している問題・エラーメッセージ
初期値を0として
+1追加ボタンをクリックすると最初に
①index.php?action=remove&month=%7Bmonth%7D
が表示される。
さらにクリックすれば、正常。
②index.php?action=remove&month=01
になる。
以降ボタンクリックするたびにindex.php?action=remove&month=数字
※数字がカウントされる。
該当のソースコード
PHP
1config.php 2 3define("EXPLODE","<explode>");
PHP
1function.php 2 3function explode_h($html_path){ 4 $html = file_get_contents($html_path); 5 $s_html = explode(EXPLODE, $html); 6 7 return $s_html; 8} 9 10function YearMonthChange($av_month,$s_html,$branch){ 11 12 $month = $av_month; 13 if(array_key_exists("month",$_GET) && ctype_digit($_GET["month"])){ 14 if($branch==='increase'){ 15 $month = $_GET["month"]+1; 16 }elseif($branch==='decrease'){ 17 $month = $_GET["month"]-1; 18 } 19 } 20 $html = $s_html[4]; 21 $html = str_replace("{month}", $month, $html); 22 return $html; 23} 24 25 26
php
1index.php 2 for ($i = 0; $i < 6; $i++) { 3 $v_html[$i] = $s_html[$i];//s_htmlを雛型として読み込み、$v_htmlで加工 4 } 5$av_Year = date('Y');//今年 6$av_month= date('m');//今月 7 8$ActionGet = $_GET['action']; 9 10if (isset($ActionGet)) {//先月、今月、来月ボタンを押すまでは実行しない 11 if ($ActionGet === 'remove') { 12 $v_html[4] = YearMonthChange($av_month,$s_html,'decrease'); 13 14 } elseif ($ActionGet === 'add'){ 15 $v_html[4] = YearMonthChange($av_month,$s_html,'increase'); 16 17 } elseif ($ActionGet === 'nowMonth'){ 18 header('Location: index.php'); 19 exit(); 20 } 21 } 22}else{//今月表示処理 23}
html
1$v_html[4]の内容 2 3<explode> 4<form action="" method="GET"> 5<button type="submit" name="action" value="remove">先月</button> 6<button type="submit" name="action" value="nowMonth">今月</button> 7<button type="submit" name="action" value="add">来月</button> 8 9<input type="hidden" name="month" value="{month}"> 10 11</form> 12 13 14<explode>
試したこと
file_get_contentsを入れないコード(別スレ(URL先のコード内容通り))で発生している問題の①はないのですが、どうしてもfile_get_contentsを入れておきたいので解決方法が思いつきませんでした・・
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/03 02:17
2018/04/03 02:26
2018/04/03 02:31