phpでフォーム入力後
1ページ目は結果が正常に表示されるのですが
2ページ以降が検索ワードを伴う結果が表示されません
何度もすいませんが調べても分からなかったのでアドバイスお願いします・・・
//次ページやページング処理
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>天気予報を表示する</title> </head> <body> <?php $filename = 'test.txt'; $filename = 'sst.txt'; $filename = 'gyousuu.txt'; $filename2 = 'RSSlog.txt'; $i = 0;//総検索済み回数 $v = 0;// function Filewriteでつかう存在する動画の通し番号(0,1,2,3,4,5・・・・) $j = 0;// function Filewrite存在する動画の通し番号(0,1,2,3,4,5・・・・) $p=0; $size= 100;//動画取得数 if( isset($_GET['page']) ){ //サニタイズ 数値なら代入、違えば1 if( is_numeric($_GET['page']) ){ $p=$_GET['page']; } } function kensakumado(){ global $x,$v,$size,$p,$nm;// 通し番号を付けとく echo "<form action = '?page=0' method='get'>"; echo "名前:<input type='text' name='nm'>"; echo "年齢:<input type='text' name='age'>"; echo "<input type='submit' name='exec' value='検索'>"; echo "</form>"; $nm =htmlspecialchars($_GET['nm']); } function OnedaySerchSQL(){ global $x,$v,$size,$p,$nm;// 通し番号を付けとく global $tousi; $v+=1; $nowstamp=time(); date_default_timezone_set('Asia/Tokyo'); $time=date( "Y年m月d日 H時i分s秒" ) ; $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('接続失敗です。'.mysql_error()); } print('<p>接続に成功しました。</p>'); $db_selected = mysql_select_db('nikonikodouga', $link); if (!$db_selected){ die('データベース選択失敗です。'.mysql_error()); } print('<p>uriageデータベースを選択しました。</p>'); mysql_set_charset('utf8'); $result = mysql_query('SELECT * FROM rss'); if (!$result) { die('クエリーが失敗しました。'.mysql_error()); } $sql = "SELECT title,syutokuzumi,syutokuTIME,smtsuzuki,timestamp FROM rss where title like '%$nm%'limit " . $p*10 . ", 10 ";//10件ずつ表示する。次ページ押すとGETから変数pに+1される $result_flag = mysql_query($sql); $i = 0; while ($row = mysql_fetch_assoc($result_flag)) { if($i>=$size)break; print('<p>'); print('title='.$row['title']); print(',syutokuzumi='.$row['syutokuzumi']); print(',syutokuTIME='.$row['syutokuTIME']); print(',smtsuzuki='.$row['smtsuzuki']); print('</p>'); $x[$i]->URL = $row['smtsuzuki']; $x[$i]->RSSsyutokuTime = $row['syutokuTIME']; $x[$i]->RSStimestamp = $row['timestamp']; $i++; } $close_flag = mysql_close($link); if ($close_flag){ print('<p>切断に成功しました。</p>'); } return $i; } class A { public $num; public $sm; public $imgurl; public $tltle; public $setsumei; public $view; public $mylist; public $coment; public $URL; public $tag; public $RSSsyutokuTime; public $RSStimestamp; } for($i=0 ; $i<=$size; $i++) { $x[$i] = new A; } kensakumado(); OnedaySerchSQL(); ?><a href="?page=<?php echo $p+1; ?>">次へ</a>
<?php $start_page = ($p < 4 ? 0 : ($p >= ($size - 4) ? $size - 8 : $p - 4)); // 4 <= $p <= ($size - 4) $end_page = $start_page + 9; //奇数にして選択ページの前後のリンク数を同じにしてあります for($i = $start_page; $i < $end_page; $i++){ if($i == $p){ echo $i; }else{ echo "<a href=?page={$i}>{$i}</a> "; } } ?> </body> </html>回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/08 12:32
2016/03/08 12:34