タイトルだけですとわかりにくいですが、こちらで説明いたします。
まずコードをご覧ください。
1.index.phpで詳細のところをリンクいれてます。目的はクリックすると、その番号の日付やID、入力値をinfo.phpで表示したいですが、今はクリックするとすべてのデータの日付、IDと入力値が表示してしまいます。
2.たとえでいいますと、1番のところの詳細をクリックすると、ページ遷移し、そのページでID1番の情報のみ出してほしいです。
3.dbから取得した日付は全部2017-03-15 13:13:00のようになってますが、それを2017年3月15日のように表示したいです。substr_replaceで置換できるみたいですが、同じ[-]をどうすれば月は年に置換ができますか?もし[-]を年に置換したら2017年03年になりますが、ほか方法はないでしょうか?
ヒントもしくは似たような記事を書いた参考ページ頂けたら幸いです。
回答よろしくお願いいたします。
index.php
php
1<html> 2<head> 3<title>DB</title> 4<link rel="stylesheet" type="text/css" href="css.css"> 5</head> 6<body> 7 8<form method="post" name="form" action="info.php"> 9<input type="text" name="name"></input> 10<input type="submit"></button> 11</form> 12 13<table border="2" cellspacing="10" width="200px"> 14 <tr> 15 <th scope="col">ID</th> 16 <th scope="col">入力値</th> 17 <th scope="col">詳細</th> 18 </tr> 19<?php 20 21$link = mysql_connect('localhost', 'root', ''); 22if (!$link) { 23 die('接続失敗です。'.mysql_error()); 24} 25 26 27 28$db_selected = mysql_select_db('kadai', $link); 29if (!$db_selected){ 30 die('データベース選択失敗です。'.mysql_error()); 31} 32 33 34 35mysql_set_charset('utf8'); 36 37$result = mysql_query('SELECT id,name FROM user'); 38if (!$result) { 39 die('クエリーが失敗しました。'.mysql_error()); 40} 41 42while ($row = mysql_fetch_assoc($result)) { 43 ?> 44 45 <tr> 46 <td><?php print(htmlspecialchars($row['id']));?></td> 47 <td><?php print(htmlspecialchars($row['name']));?></td> 48 <td id="ss"><a href="info.php">詳細</a></td> 49</tr> 50<?php 51} 52$close_flag = mysql_close($link); 53 54if ($close_flag){ 55 print('<p>切断に成功しました。</p>'); 56} 57 58?> 59</body> 60</html>
info.php
php
1<html> 2<head> 3<title>DB</title> 4</head> 5<body> 6 7 8 <?php 9 10$link = mysql_connect('localhost', 'root', ''); 11if (!$link) { 12 die('接続失敗です。'.mysql_error()); 13} 14 15 16 17$db_selected = mysql_select_db('kadai', $link); 18if (!$db_selected){ 19 die('データベース選択失敗です。'.mysql_error()); 20} 21 22mysql_set_charset('utf8'); 23?> 24 25<?php 26$result = mysql_query('SELECT * FROM user'); 27if (!$result) { 28 die('クエリーが失敗しました。'.mysql_error()); 29} 30 31while ($row = mysql_fetch_assoc($result)) { 32 ?> 33<table border="1" cellspacing="10" width="200px"> 34 <tr> 35 <th>ID</th> 36 <td><?php print(htmlspecialchars($row['id']));?></td> 37 </tr> 38 <tr> 39 <th>入力値</th> 40 <td><?php print(htmlspecialchars($row['name']));?></td> 41 </tr> 42 <tr> 43 <th>詳細</th> 44 <td><?php print(htmlspecialchars($row['ins_date']));?></td> 45 </tr> 46 47 48 49<?php 50} 51$close_flag = mysql_close($link); 52 53if ($close_flag){ 54 print('<p>切断に成功しました。</p>'); 55} 56 57?> 58</body> 59</html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/15 06:52