同じコードを使っているのにエラーはなぜ?

このQ&Aのポイント
  • 先日、似たような質問をいたしました。エラーが出る理由を教えてください。
  • コード内の3行目でエラーが出ています。該当のコードの意味とエラーの原因を教えてください。
  • 参考文献の書籍のコードを書いていますが、エラーが出ます。どうすればエラーをなくすことができますか?
回答を見る
  • ベストアンサー

同じコードを使っているのにエラーはなぜ?

●質問の意味 先日、似たような質問をいたしました。 「未定義の変数」の定義について(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
  • 回答数3
  • ありがとう数3

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

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

何度同じミスをすればいいのか・・・ <?php require('dbconnect.php); $id = isset($_GET['id']) ? intval($_GET['id']) : 1; 3行目じゃなくて、1行前の require('dbconnect.php); 『いつものように』引用符が閉じていない。 正直、プログラミングには向いていないと思う。諦めるなら早い方がいい。

dradra33
質問者

お礼

agunuzさま。 ご回答とご指摘ありがとうございます。 require('dbconnect.php); 引用符がありませんでしたね…。 まことに恐れ入ります。 他の方に質問する前にeclipseでの使用などで、 凡ミスに気付く習慣を身につけるようにします。

dradra33
質問者

補足

なお、引用符を付けたうえで、 require('dbconnect.php'); $id = isset($_GET['id']) ? intval($_GET['id']) : 1; としたら、意図通りの画面が表示されました。 ありがとうございます。

その他の回答 (2)

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

全くの蛇足ですが $page = isset($_GET['page']) ? intval($_GET['page']) : 1; としているのであれば、 if ($page == '') { $page = 1; } は不要ですよね。必ずなんらかの整数値がセットされますし、その次にmaxもあるのですから。極端な話、maxまで含めて $page = isset($_GET['page']) ? max(intval($_GET['page']),1) : 1; でもいいと思います。 閑話休題 >Parse error: syntax error, unexpected 'id' (T_STRING) in >C:\xampp\htdocs\shop\update.php on line 3 このエラーメッセージ(と行番号)は間違いありませんか?3行目はコメントアウトだし id というリテラルが見当たりません(気になるとすればrequireしている dbconnect.php がどうなっているのかくらいでしょうか・・・)。 提示されているソースが「C:\xampp\htdocs\shop\update.php」ということで間違いありませんか?どう考えてもupdate.phpというスクリプト名の内容にはなっていないように思えます(updateする部分がどこにもない)。

dradra33
質問者

お礼

agunuzさま いつもご回答・ご指摘ありがとうございます >このエラーメッセージ(と行番号)は間違いありませんか? あげるべきupdate.phpのソースコードを間違えておりました。 正しくは、以下のとおりです。 (コメントアウトは参考文献のコードです) update.php <?php require('dbconnect.php); $id = isset($_GET['id']) ? intval($_GET['id']) : 1; //$id = $_REQUEST['id']; $sql = sprintf("SELECT * FROM my_items WHERE id=%d", mysql_real_escape_string($id) ); $recordSet = mysql_query($sql); $data = my_sql_fetc_assoc($recordSet); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>商品情報変更</title> </head> <body> <div id="wrap"> <div id="head"> <h1>商品情報変更</h1> </div> <div id="content"> <p>変更する内容を記入してください。</p> <form id="frmUpdate" name="frmUpdate" method="post" action="up_date.php"> <dl> <dt> <label for="maker_id">メーカーID</label> </dt> <dd> <input name="maker_id" type="text" id="maker_id" size="10" maxlength="10" value="<?php print<htmlspecialchars($data['maker_id'], ENT_QUOTES)); ?>" /> </dd> <dt> <label for="item_name">商品名</label> </dt> <dd> <input name="item_name" type="text" id="item_name" size="35" maxlength="255" value="<?php print<htmlspecialchars($data['item_name'], ENT_QUOTES)); ?>" /> </dd> <dt> <label for="price">価格</label> </dt> <dd> <input name="price" type="text" id="price" size="10" maxlength="10" value="<?php print<htmlspecialchars($data['price'], ENT_QUOTES)); ?>" /> 円</dd> <dt> <label for="keyword">キーワード</label> </dt> <dd> <input name="keyword" type="text" id="keyword" size="50" maxlength="255" value="<?php print<htmlspecialchars($data['keyword'], ENT_QUOTES)); ?>" /> </dd> <input type="submit" value="変更する" /> <input type="hidden" name="id" value="<?php print(htmlspecialchars($data['id'], ENT_QUOTE)); ?>" /> </form> </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>

dradra33
質問者

補足

補足です。 〉 if ($page == '') { $page = 1; } 〉は不要ですよね。必ずなんらかの整数値がセットされますし、その次にmaxもあるのですから。極端な話、maxまで含めて ご指摘の通りです。 この箇所を削除しても全く問題はありませんでした。 大変参考になりました。ありがとうございます。

  • yambejp
  • ベストアンサー率51% (3827/7415)
回答No.1

エラーメッセージは?

dradra33
質問者

お礼

yambejpさま ご回答&ご指摘ありがとうございます。 エラーメッセージは次のとおりです↓ Parse error: syntax error, unexpected 'id' (T_STRING) in C:\xampp\htdocs\shop\update.php on line 3

関連する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)

    ●質問の主旨 添付画像の左端に 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
  • テーブルの情報が一部しか表示されません。(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
  • 【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
  • 簡易データベースについて

     ___________________ |画像|詳細       | |● |詳細をみる    | |● |詳細をみる    | |● |詳細をみる    | 上記のようなイメージにしたいのですが、下のコードだと 新たにテーブルを作り ________ |画像|詳細   |  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ |● |詳細を見る|  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ________ |画像|詳細   |  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ |● |詳細を見る|  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ________ |画像|詳細   |  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ |● |詳細を見る|  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ のようになってしまいます。どうぞよろしくお願いします <form action="search.php" method="GET"> <input type="text" name="key"> <input type="submit" name="submit" value="検索"> </form> <p> <!--ここから検索結果--> <?php if($_GET["key"]!=""){ $KeyWord=$_GET["key"]; $KeyWord=htmlspecialchars($KeyWord); $Data=file("item.csv"); for($i=0;$i<sizeof($Data);$i++){ $lines=strip_tags($Data[$i]); if(mb_eregi($KeyWord,$lines)){ $line=explode(",",$Data[$i]); ?> </p> <table width="500" height="249" border="1"> <tr> <th width="161" scope="col">画像</th> <th width="323" scope="col">詳細</th> </tr> <tr> <th scope="row"><?=$line[3]?></th> <td><div align="center"><a href="item.php?id=<?=$line[0]?>">詳細を見る</a></div></td> </tr> </table> <p> <?php } } } ?> </th> </tr> </table>

    • ベストアンサー
    • PHP
  • style=displayでの表示/非表示切り替え

    テーブルで表示させている内容をJavaScriptを使って行ごとに表示/非表示の切り替えができるようにしたのですが、表示させた時、IEでは通常のテーブル表示のように表示されるのですが、FirefoxやSafariでは何故かテーブルの一番左の<tr>要素内に全ての<td>要素が入る形で表示されてしまいます。多分CSSの書き方に関係していると思われるのですが、どなたか分かる方アドバイスをお願い致します。 下記は、コードの抜粋です。 [CSS] (略) #content { padding: 10px 0; width: 780px; float: left; } #inquiry { width: 600px; /* ボックスの幅を指定 */ margin-left: auto; margin-right: auto; } #inquiry table { border-top: 1px solid #CCCCCC; border-bottom: none; border-left: none; border-right: 1px solid #CCCCCC; font-size: 100%; width: 100%; } #inquiry td { border-top: none; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: none; padding: 10px; text-align: center; } #inquiry th { border-top: none; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: none; background-color: #F3F3F3; font-weight: normal; padding: 10px; } (略) [HTML] (略) <script type="text/javascript" src="../../webroot/js/prototype.js"></script> <script type="text/javascript"> <!-- function OnScreenHelp(id){ var elem = document.getElementsByClassName(id); for(var i=0;i<elem.length;i++) { elem[i].style.display = elem[i].style.display == "none" ? "block" : "none"; } } //--> </script> (略) <table border="border" summary="購入履歴" cellspacing="0"> <caption><h3>購入履歴</h3></caption> <tr> <th scope="col"><label for="name">注文番号</label></th> <th scope="col"><label for="name">ご注文日</label></th> <th scope="col"><label for="name">合計金額</label></th> <th scope="col"><label for="name">備考</label></th> </tr> <?php foreach($data1 as $row1) { $id = $row1['Order']['id']; ?> <tr onclick="OnScreenHelp(<?php echo $id; ?>)"> <td><?php echo h($row1['Order']['id']); ?></td> <td><?php echo h($row1['Order']['orderdate']); ?></td> <td><?php echo h($row1['Order']['total']); ?></td> <td><input type="text" name="name" size="30" id="name" class="text1" value="送料込み" /></td> </tr> <?php } ?> </table><br /> <table border="border" summary="明細情報" cellspacing="0"> <caption><h3>明細</h3></caption> <tr> <th scope="col"><label for="customerno">商品番号</label></th> <th scope="col"><label for="name">商品名</label></th> <th scope="col"><label for="price">価格</label></th> <th scope="col"><label for="quantity">数量</label></th> <th scope="col"><label for="subtotal">小計</label></th> </tr> <?php foreach($data2 as $row2) { $id = $row2['Orderitem']['order_id']; ?> <tr class="<?php echo $id; ?>" style="display:none;"> <td><?php echo h($row2['Product']['productno']); ?></td> <td><?php echo h($row2['Product']['name']); ?></td> <td><?php echo h($row2['Product']['price']); ?></td> <td><?php echo h($row2['Orderitem']['quantity']); ?></td> <td><?php echo h($row2['Orderitem']['subtotal']); ?></td> </tr> <?php } ?> </table> (略)

    • ベストアンサー
    • CSS
  • 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

専門家に質問してみよう