未定義の変数の定義について(PHP)

このQ&Aのポイント
  • 「未定義の変数」の表示を消す方法についてご教示ください。
  • 下記のコードで「未定義の変数」というエラーが表示されます。このエラーを取り除く方法を教えてください。
  • PHPのコードで「Notice: Undefined index: page」というエラーが表示されます。このエラーを解消する方法を教えてください。
回答を見る
  • ベストアンサー

「未定義の変数」の定義について(PHP)

●質問の主旨 添付画像の左端に Notice: Undefined index: page in C:\xampp\htdocs\shop\index.php on line 3 ということで、未定義の変数ということでおしらせが出ています。 この表示を消すためにはどうすれば良いでしょうか? ご存知のかた、ご教示願います。 ●質問の補足 下記のコードで言えば、 $page =$_REQUEST['page']; のうち、pageが定義されていないことが、表示の原因である気がします。 しかし、どこをどう書き換えれば、表示が消えるのかが分かりません。 ●参考文献 たにぐちまこと「よくわかるPHPの教科書」(P210)の index.phpファイル ●開発環境 windows8 xammp1.8.1 ●コード <?php require('dbconnect.php'); $page =$_REQUEST['page']; if ($page == '') { $page = 1; } $page = max($page, 1); //最終ページを取得する $sql = 'SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysql_query($sql); $table = mysql_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] / 5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysql_query('SELECT m.name, i. * FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start .',5'); ?> <!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Webシステムをつくる</title> </head> <body> <div id="wrap"> <div id="head"> <h1>トップページ</h1> </div> <div id="content"> <p style="margin-top: 20px"> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> </tr> <?php } ?> </table> <ul class="paging"> <?php if ($page > 1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ</a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if ($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ</a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> </p> </div> <div id="foot"> <p><img src="images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p> </div> </div> </body> </html>

  • PHP
  • 回答数2
  • ありがとう数4

質問者が選んだベストアンサー

  • ベストアンサー
  • agunuz
  • ベストアンサー率65% (288/438)
回答No.2

>Notice: Undefined index: page in C:\xampp\htdocs\shop\index.php on line 3 >ということで、未定義の変数ということでおしらせが出ています。 未定義の添え字ですね(未定義の変数の場合はUndefined variables となります)。 ブラウザから投稿される変数に関してはisset()で存在を確認してから使うのが基本です。また「GET/POSTの両方のケースがある」のでもない限りは$_REQUESTは使わずに$_GETもしくは$_POSTで書きます。このスクリプトだと$_GETだけではないですかね。 $page = isset($_GET['page']) ? intval($_GET['page']) : 1; なお、ネイティブなMySQL関数は先がありません。古い書籍などでMySQL関数しか書いていないものであれば自分で『PDOなどに書き替える』ことをやっておくといいです。

dradra33
質問者

お礼

agunuzさま いつもご回答ありがとうございます! $page =$_REQUEST['page']; を $page = isset($_GET['page']) ? intval($_GET['page']) : 1; に置き換えたら "Notice"が消えました。アドバイス助かります。 またPDOについてよくわからないので、 自分で調べてみます。

その他の回答 (1)

回答No.1

$page =$_REQUEST['page']; $_REQUESTにpageがあるかどうか調べれば良いのでは? if(isset($_REQUEST['page']){   $page=$_REQUEST['page']; }else{   $page=""; } もしくはphp.iniでdisplay_errors = Offでエラー表示しないとか error_reporting = E_ALL & ~E_NOTICEでnoticeだけ非表示とか phpファイルの頭でerror_reporting(E_ALL & ~E_NOTICE);とか

dradra33
質問者

お礼

CyberCypherさま ご回答ありがとうございます。 "Notice"そのものについては、 No.2のご回答で解決することができました。 php.iniファイルで エラーの範囲の決める方法については、 今後の参考にさせていただきます。 アドバイス助かります。

関連するQ&A

  • よくわかるPHPの教科書のエラー?について

    わからないところがあるので教えて下さい。 (コード) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. w3.org/TR/xhtmll/DTD/xhtmll- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>PHP入門</title> </head> <body> <?php require('dbconnect.php'); $page = $_REQUEST['page']; if($page =='') { $page =1; } $page = max($page, 1); //最終ページを取得する $sql ='SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysqli_query($db, $sql); $table = mysqli_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] /5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysqli_query($db, 'SELECT m.name, i.* FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start . ',5'); ?> <p><a href="input.php">新しい商品を登録する。</a></p> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> <th scope="col">編集・削除</th> </tr> <?php while($table = mysqli_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> <td><a href="update.php?id=<?php print(htmlspecialchars($table['id'])); ?>">編集</a> <a href="delete.php?id=<?php print(htmlspecialchars($table['id'])); ?>" onclick="return confirm('削除してもよろしいですか?');">削除</a> </td> </tr> <?php } ?> </table> <ul class="paging"> <?php if($page > 1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ </a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ </a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> </body> </html> 参考書?はよくわかるPHPの教科書5.5対応なのですが、一番初めにこのファイルを開くと Notice: Undefined index: page in C:\xampp\htdocs\shop\index.php on line 14っとエラー?が出ます。 次のページ、前のページを押すとエラー?は消えるのですが、とっても気になります。 なるべくなら、エラーを非表示にせずにプログラム内で問題を解決したいのですが・・・ 初心者なのでどうして良いかわかりません。 出来れば、とってもわかりやすい解決を出来ればお願いしたいです。(馬鹿なので・・・) よろしくお願いします。

    • ベストアンサー
    • PHP
  • 同じコードを使っているのにエラーはなぜ?

    ●質問の意味 先日、似たような質問をいたしました。 「未定義の変数」の定義について(PHP) http://okwave.jp/qa/q8060182.html それと同じようなコードを書いていますが、 エラーが出ます。なぜでしょうか? ご存知の方、よろしくお願いします。 ●質問の補足 下記のコードの3行目 $page = isset($_GET['page']) ? intval($_GET['page']) : 1; についてエラーが出ています。 コメントアウトしている //$page =$_REQUEST['page']; は、参考文献の方のコードですがこちらでもエラーが出ます。 ●参考文献 たにぐちまこと「よくわかるPHPの教科書」(P215)の update.phpファイル ●開発環境 windows8 xammp1.8.1 ●コード(update.php) <?php require('dbconnect.php'); //$page =$_REQUEST['page']; $page = isset($_GET['page']) ? intval($_GET['page']) : 1; if ($page == '') { $page = 1; } $page = max($page, 1); //最終ページを取得する $sql = 'SELECT COUNT(*) AS cnt FROM my_items'; $recordSet = mysql_query($sql); $table = mysql_fetch_assoc($recordSet); $maxPage = ceil($table['cnt'] / 5); $page = min($page, $maxPage); $start = ($page - 1) * 5; $recordSet = mysql_query('SELECT m.name, i. * FROM makers m, my_items i WHERE m.id=i.maker_id ORDER BY id DESC LIMIT ' . $start .',5'); ?> <!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Webシステムをつくる</title> </head> <body> <div id="wrap"> <div id="head"> <h1>トップページ</h1> </div> <div id="content"> <p style="margin-top: 20px"> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['item_name'])); ?></td> <td><?php print(htmlspecialchars($table['price'])); ?></td> </tr> <?php } ?> </table> <ul class="paging"> <?php if ($page > 1) { ?> <li><a href="index.php?page=<?php print($page - 1); ?>">前のページへ</a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if ($page < $maxPage) { ?> <li><a href="index.php?page=<?php print($page + 1); ?>">次のページへ</a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> </ul> </p> </div> <div id="foot"> <p><img src="images/txt_copyright.png" width="136" height="15" alt="(C) H2O Space. MYCOM" /></p> </div> </div> </body> </html>

    • ベストアンサー
    • PHP
  • テーブルの情報が一部しか表示されません。(php)

    すべてのID分の提出状況を表示させたい("○"か"×")のですが、 id=1の提出状況しか表示されません。 テストデータはid=5までの5件を入力しています。 $recordSet2 = mysql_query('SELECT * FROM report'); をwhileにいれてみたり試行錯誤してみたのですが、上手くいきません。 ご指摘よろしくお願い致します。 プログラム <table width="70%"> <tr> <th scope="col"><bl>ID</bl></th> <th scope="col"><bl>教科名</bl></th> <th scope="col"><bl>課題名</bl></th> <th scope="col"><bl>担当教員</bl></th> <th scope="col"><bl>提出期限</bl></th> <th scope="col"><bl>再提出</bl></th> <th scope="col"><bl>再提出期限</bl></th> <th scope="col"><bl>提出状況</bl></th> </tr> <?php $recordSet = mysql_query('SELECT * FROM exercise ORDER BY id'); while ($table = mysql_fetch_assoc($recordSet)){ ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['lessonname'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['teacher'])); ?></td> <td><?php print(htmlspecialchars($table['presentday'])); ?></td> <td><?php print(htmlspecialchars($table['represent'])); ?></td> <td><?php print(htmlspecialchars($table['representday'])); ?></td> <td><?php $recordSet2 = mysql_query('SELECT * FROM report'); $report = mysql_fetch_assoc($recordSet2); if ($table['lessonname'] == $report['lessonname'] && $table['name'] == $report['exercisename']) { if(eregi($member['name'], $report['upfile'])) { echo "○"; }else { echo "×"; } } ?></td> </tr> <?php } ?> </table>

    • ベストアンサー
    • PHP
  • テーブルの情報が一部しか表示されません。(php)

    すべてのID分の提出状況を表示させたい("○"か"×")のですが、 id=1の提出状況しか表示されません。 >>CODE $recordSet2 = mysql_query('SELECT * FROM report'); <<CODE をwhileにいれてみたり試行錯誤してみたのですが、上手くいきません。 ご指摘よろしくお願い致します。 プログラム >>CODE <table width="70%"> <tr> <th scope="col"><bl>ID</bl></th> <th scope="col"><bl>教科名</bl></th> <th scope="col"><bl>課題名</bl></th> <th scope="col"><bl>担当教員</bl></th> <th scope="col"><bl>提出期限</bl></th> <th scope="col"><bl>再提出</bl></th> <th scope="col"><bl>再提出期限</bl></th> <th scope="col"><bl>提出状況</bl></th> </tr> <?php $recordSet = mysql_query('SELECT * FROM exercise ORDER BY id'); while ($table = mysql_fetch_assoc($recordSet)){ ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></td> <td><?php print(htmlspecialchars($table['lessonname'])); ?></td> <td><?php print(htmlspecialchars($table['name'])); ?></td> <td><?php print(htmlspecialchars($table['teacher'])); ?></td> <td><?php print(htmlspecialchars($table['presentday'])); ?></td> <td><?php print(htmlspecialchars($table['represent'])); ?></td> <td><?php print(htmlspecialchars($table['representday'])); ?></td> <td><?php $recordSet2 = mysql_query('SELECT * FROM report'); $report = mysql_fetch_assoc($recordSet2); if ($table['lessonname'] == $report['lessonname'] && $table['name'] == $report['exercisename']) { if(eregi($member['name'], $report['upfile'])) { echo "○"; }else { echo "×"; } } ?></td> </tr> <?php } ?> </table> <<CODE

    • ベストアンサー
    • PHP
  • phpのエラーについてです

    mysql上のデータをphpでブラウザに表示するコードを書いています。 下記のプログラムを実行した所 Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampplite\htdocs\shop\index.php on line 18 というようなエラーが表示されます。 本の通りに進めているので間違っていないはずなんですが・・ どこが成立していないのでしょうか??? <?php mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('mydb'); mysql_query('SET NAMES UTF8'); $recordSet = mysql_query('SELECT m.name, i.* FROM makers m, my_ items i WHERE m.id=i.maker_id ORDER BY id DESC'); ?> <table width="100%"> <tr> <th scope="col">ID</th> <th scope="col">メーカー</th> <th scope="col">商品名</th> <th scope="col">価格</th> </tr> <?php while ($table = mysql_fetch_assoc($recordSet)) { ?> <tr> <td><?php print(htmlspecialchars($table['id'])); ?></tb> <td><?php print(htmlspecialchars($table['name'])); ?></tb> <td><?php print(htmlspecialchars($table['item'])); ?></tb> <td><?php print(htmlspecialchars($table['price'])); ?></tb> </tr> <?php } ?> </table>

    • ベストアンサー
    • PHP
  • PHPでtableをループさせたい!

    【急募!】PHPでMysqlから取り出した値をHTMLのtableで出力したい。 うまくいかなくて困ってます。 今回で2度目の質問となります。今回も急いでおります。 現在、プログラムの勉強をして半年近くになります。本日3/3までに作成を完了しなければならず困っております。 何日か掛けて調べたのですが、まだまだ勉強不足の為に理解が出来ませんでした。 PHPで作成をしております。データベースから取り出した値をHTMLで作成したtableに出力後、tableをデータベースに入っている数だけループさせたいです。※イメージ画像あり おそらくwhile分でループさせれば良いとういうのは理解できるのですが、テーブル自体を増やすやりかたかが解りません。 while(データーベースの値をループさせてひとつずつ出力する。,テーブルも同じ数出力する) 全部取り出したら break で抜ける......となると思うのですが、書き方か解りません。 mysql_fetch_arrayというものもあるようですがまだ理解ができません。 答え合わせになってしまうのが恐縮でございますが、答え合わせのコードを頂けましたら嬉しいです。 まだ理解が浅いため、質問の内容に理解が出来なければ、ご連絡を頂きましたら改善改良をします。 お恥ずかしいですが、ソースを乗せさせて頂きますので宜しくお願い致します。 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link href="css/style2.css" rel="stylesheet" type="text/css"> <title>管理画面</title> </head> <body> <div id="main"> <?php $dsn='mysql:dbname=motorlinks;host=localhost'; $user='root'; $password=''; $dbh=new PDO($dsn,$user,$password); $dbh->query('SET NAMES utf8'); $sql='SELECT code,gazou,name,shiyo,price,shiharai,first,sample,comment FROM pone WHERE 1'; $stmt=$dbh->prepare($sql); $stmt->execute(); print'製品一覧<br><br>'; print'<form method="post"action="pone_branch.php">'; ?> <?php while(true) { $rec=$stmt->fetch(PDO::FETCH_ASSOC); if($rec==false) { break; } print $rec['gazou']; print $rec['name']; print $rec['shiyo']; print $rec['price'].'円'; print $rec['shiharai']; print $rec['first']; print $rec['sample']; print $rec['comment']; print'<br>'; }?> <table width="800" border="1" cellpadding="0"> <?php print'<input type="radio"name="ponecode"value="'.$rec['code'].'">'; ?> <tr> <th colspan="2" rowspan="4" scope="col"><?php '<img src="gazou/burank.jpg" width="200" height="150" alt=""/>'; ?></th> <th width="162" height="4" scope="col">Product Name</th> <th width="162" height="4" scope="col">Specification</th> <th width="162" height="4" scope="col">Price</th> <th width="162" height="4" scope="col">Payment</th> </tr> <tr> <td height="63">&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <th width="162" height="4" scope="col">First Order</th> <th width="162" height="4" scope="col">Sample</th> <th width="162" height="4" scope="col">Comment</th> <th width="162" height="4" scope="col">Contact</th> </tr> <tr> <td height=63">&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </table> <?php print'<br>'; print'<input type="submit" name="disp" value="参照">'; print'<input type="submit" name="add" value="追加">'; print'<input type="submit" name="edit" value="修正">'; print'<input type="submit" name="delete" value="削除">'; print'</form>'; ?> <br> <a href="index_mo.html">トップメニューへ</a><br> </form> </div> </body> </html>

    • ベストアンサー
    • PHP
  • $_SESSIONの取りだし方、使い方PHP

    質問失礼いたします。 【1.html】から【A.php】に$_POSTされた値を、$_SESSIONにて下記の通りに格納しています。 $name = $_POST['name']; $_SESSION['name'] = $_POST['name']; $address = $_POST['address']; $_SESSION['address'] = $_POST['address']; $gender = $_POST['gender']; $_SESSION['gender'] = $_POST['gender']; そして、上記の$_POSTされた値を使って、データを検索し20件ずつ表示させて改ページを行っています。 <?php if ($page > 1) { ?> <li><a href="search2.php?page=<?php print($page - 1); ?>">前のページへ</a></li> <?php } else { ?> <li>前のページへ</li> <?php } ?> <?php if ($page < $maxPage) { ?> <li><a href="search2.php?page=<?php print($page + 1); ?>">次のページへ</a></li> <?php } else { ?> <li>次のページへ</li> <?php } ?> 違うかもしれませんが、 アドレスに  &name=○&address=○&gender=○  という風にして、次のページではアドレスにある値を使う みたいなこととは思うのですが、   &name=<?php print($name; ?> とすると、アドレスでは  &name=Array となってしまいます。 セッションに格納した検索条件を次のページにも使うようにはどのようにすればよいのでしょうか。 また、上記の次ページのアドレスに、  &name=○&address=○&gender=○  と表示しないようなやり方もあるのでしょうか?

    • ベストアンサー
    • PHP
  • phpのフォームでエラーが出ます

    php初心者です。 ↓の参考サイトを参考にフォームを作ってみましたが、 ローカルサーバーでテストしてみると、inquiry.phpの最後の行(?>)に エラーがある旨のメッセージが出てしまい、 原因がわからず困っております。 どなたかおわかりになる方がいらっしゃいましたら、 よろしくお願いします。 【参考サイト】 http://php.frogstone.jp/inquiry/inquiry.php 【プログラムの構造】 index.html(メインプログラム) sendEnd.html(送信完了ページ) inquiry.php 【index.html】 <div id="form_main"> <?php echo($tagErr); ?> <form action="inquiry.php" method="post"> <input name="mode" type="hidden" value="send" /> <div class="hiss"> <p>※印は必須項目です。</p> </div> <table> <tr> <th scope="row">お名前<b class="hiss">※</b></th> <td><input type="text" name="name" value="" class="m" id="name"/></td> </tr> <tr> <th scope="row">会社名</th> <td><input type="text" name="company" value="" class="m" id="company"/></td> </tr> <tr> <th scope="row">お電話番号<b class="hiss">※</b></th> <td><input type="text" name="tel" value="" class="" id="tel"/></td> </tr> <tr> <th scope="row">メールアドレス<b class="hiss">※</b></th> <td><input type="text" name="mail" value="" class="" id="mail"/></td> </tr> <tr> <th scope="row">お問い合わせ内容<b class="hiss">※</b></th> <td><textarea name="naiyo" cols="10" rows="10" class="L" id="naiyo"></textarea></td> </tr> </table> <div class="align_c"><input type="submit" name="submit" value="確認画面へ進む" class="input-b"/></div> </form> </div> 【inquiry.php】 <?php #設定 $adminMail = "test@test.com"; #データの受け取り foreach($_REQUEST as $key => $value) { $value = mb_convert_kana($value,"rkv"); $FORM[$key] = $value; } #フォームから送信された場合 if($FORM["mode"] == "send") { #入力エラーチェック $flgErr = true; $tagErr = ""; if($FORM["name"] == "") { $flgErr = false; $tagErr = "<li>お名前をご記入ください。</li>\n"; } if($FORM["mail"] == "" && $FORM["tel"] == "") { $flgErr = false; $tagErr .= "<li>お電話番号かメールアドレスをご記入ください。</li>\n"; } if($FORM["naiyo"] == "") { $flgErr = false; $tagErr .= "<li>お問い合わせ内容をご記入ください。</li>\n"; } #入力エラーがあれば if(!$flgErr) { #エラーメッセージ設定 $tagErr = '<p><img src="../common/enterErr.jpg"></p><ul>'.$tagErr.'</ul>; #入力エラーがなければ } else { #管理者にメール送信 mb_language("japanese"); $subject ="お問い合わせがありました。"; $message .="お問い合わせ内容。\n\n"; $message .="お名前 :".$FORM["name"]."\n"; $message .="会社名 :".$FORM["company"]."\n"; $message .="電話番号 :".$FORM["tel"]."\n"; $message .="メールアドレス :".$FORM["mail"]."\n"; $message .="お問い合わせ内容\n".$FORM["naiyo"]."\n"; mb_send_mail($adminMail,$subject,$message,"From:".#adminMail); #完了ページへ移動 header("Location:http://localhost/test/contact/sendEnd.html"); } ?>

    • 締切済み
    • PHP
  • php 分割

    以前はmysql関数をページングを行ったのですが、今回はpdoにやりたいけど pdoに書き換えるやり方がわかりません また前回は前のページ、次のページだったのですが 15件中 1-10件表示 ○ページ表示 と行い <前 1 2 3 次>みたいにやりたいです <html> <head> <title>一覧画面</title> </head> <body> <br><br> <blockquote> 一覧画面 <br><br> <form action = "" method="GET"> <input type="hidden" name="event" value="find"> <input type="text" name="name"style ="font-size:20px;width: 400px; height: 40px"> <input type="submit" value="検索" style ="font-size:20px;width: 100px; height: 40px"> </form> <br><br> <?php if ($_GET) { // データがGETされていたら $event = isset($_GET['event']) ? $_GET['event'] : ''; // 取得 } $pdo = new PDO("mysql:dbname=db_test;host=localhost", "root", "admin"); $name=isset($_GET['name'])?$_GET['name']:""; $perpage=10; $page=isset($_GET['page'])?($_GET['page']*$perpage):0; $sql ="select * from tbl_test where 1 "; $sql.="and (0 "; $sql.="or `氏名` like concat('%',?,'%') "; $sql.="or `住所` like concat('%',?,'%') "; $sql.=") "; $sql.= " limit {$page},{$perpage}" ; $stmt = $pdo->prepare( $sql); $stmt->execute(array($name,$name)); $count = $stmt->rowCount(); if($count>0){ print "<table border=1>" ; print "<tr>"; print "<th>番号</th>"; print "<th>氏名</th>"; print "<th>住所</th>"; print "<th>操作</th>"; print "</tr>"; while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $ID = htmlspecialchars($row['番号']); $NAME = htmlspecialchars($row['氏名']); $ADDR = htmlspecialchars($row['住所']); echo "<tr> <td>$ID</td> <td>$NAME</td> <td>$ADDR</td> <td><a href='edit.php?番号=$ID'>修正</a> <a href='delete.php?番号=$ID'>削除</a></td></tr>"; print "</tr>"; }; print "</table>" ; }else{ print "該当するデータがありません"; } ?> このソースにどう命令を入れていいのかわからず困っています サンプルソースや指摘おねがいします

    • ベストアンサー
    • PHP
  • 【CSS】floatで左右に並べた<div>のマージンが効かない。

    CSS(スタイルシート)においてfloatで2つのdivを左右に並べる方法は定番ですが、<div id="A">に設定したマージンが【firefox】でききません。 おそらく基礎的なことと思われますが、検索の仕方が悪いのか、 該当する質問を探し出すことが出来ませんでしたので、質問させていただきました。 どなたか、教えていただければと思います。 【HTML】--------------------------------- <div id="A">   <div class="B">    <h3>テキスト</h3>    <p>タイトル</p>    <table>     <tr>      <th scope="col">テキスト</th>      <td>テキスト </td>     </tr>     <tr>      <th scope="col">テキスト</th>      <td>テキスト</td>     </tr>    </table>   </div>   <div class="C" >    <h3>テキスト</h3>    <p>タイトル</p>    <table>     <tr>      <th scope="col">テキスト</th>      <td>テキスト </td>     </tr>     <tr>      <th scope="col">テキスト</th>      <td>テキスト</td>     </tr>    </table>   </div> </div> 【CSS】--------------------------------- #A {     margin-bottom:10px } #A h3{ background:url(../images/bg_h3_option_half.gif) no-repeat; width:380px; height:31px; padding:0 0 0 15px; margin:10px 0 0 0; overflow:hidden; font-size: 22px; color:#FFFFFF; font-style:normal; } #A div.B { float:left; width:380px; height: 100%; margin-right:20px; } #A div.C { float:left; width:380px; height: 100%; }

    • ベストアンサー
    • HTML

専門家に質問してみよう