phpとmysqlでページング機能を用いたデータの検索ページを作成しています。
limit offset句を使いフォームから入力したデータ(緯度経度の値)に合致するデータを1件ずつ表示させていくようなプログラムを目指して作成しているのですがページを更新しても表示データが変わりません。おそらくlimit offset句の扱い方が違うと予想しているのですが改善案が見つかりません。ご教授の方よろしくお願いいたします。
<html> <title>表示結果</title> <body> <fieldset> <legend>コメント</legend> <?php //データベースに接続する変数名を宣言しておく define( 'DB_HOST', '' ); define( 'DB_USER', '' ); define( 'DB_PASS', '' ); define( 'DB_NAME', '' ); //-----ページング機能 $form_lon = $_REQUEST['longitude']; $form_lat = $_REQUEST['latitude']; //$GLOBALS["offset"] = 0; $p=0; if(isset($_GET['page'])){ if(is_numeric($_GET['page'])){ $p=$_GET['page']; //$GLOBALS["offset"]= $p; } } $com_longitude = $form_lon; $com_latitude = $form_lat; //-----下の2つの関数を使い、緯度軽度に合致したテキストを表示する。 CallImg($com_longitude,$com_latitude); //-----指定した緯度経度を持つテキストを表示する関数 function CallImg($longitude_num,$latitude_num){ print TextSearchDB($longitude_num,$latitude_num); echo nl2br("\n"); } //-----データベースから、指定した緯度経度を持つテキストファイルを検索する関数。 function TextSearchDB($longitude_num,$latitude_num){ $com_longitude_minus = $longitude_num - 0.0005; $com_longitude_plus = $longitude_num + 0.0005; $com_latitude_minus = $latitude_num - 0.0005; $com_latitude_plus = $latitude_num + 0.0005; //-----データベースへ接続する $db_link1 = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); $offset = $GLOBALS["offset"]; echo $offset; //-----指定した緯度経度のテキストを検索 $serch_query1 = mysqli_query($db_link1,"SELECT * FROM `img_table` WHERE (`longitude` BETWEEN '".$com_longitude_minus."' AND '".$com_longitude_plus."') AND (`latitude` BETWEEN '".$com_latitude_minus."' AND '".$com_latitude_plus."') ORDER BY `id_col` ASC LIMIT 1 OFFSET 0"); $row_lon = mysqli_fetch_array($serch_query1); echo $row_lon['comment']; $close_flag1 = mysqli_close($db_link1); } ?> </fieldset> <br> <fieldset> <legend>画像</legend> <!--<img src="image.php">--> </fieldset> <a href="?page= <?php echo $p+1;?> &longitude= <?php print($form_lon);?> &latitude= <?php print($form_lat);?>">次へ</a> </body> </html>
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。