前回質問させていただいた質問が抽象的かつ不明確な点があるというご指摘をいただいたので動かない部分を小分けして質問させていただきます。
・要件
現在、作業でタスク管理ができるカレンダーを作成しています。
・質問
トップページでDBにタスクをインサートした日付が自動的に別途ページのリンクが埋め込まれ、クリックで遷移できるようになります。そこで、インサートした日付のタスクをクリックして遷移したページで、その日だけのタスクを表示させる方法にアドバイスをいただければ嬉しいです。
・意見
個人的に、$_POSTで、トップページのformタグにてnameで指定された情報を遷移されたページの埋め込みたい部分でhtmlspecialcharsを用いて$_POST['~~']と記載すれば表示されると思ったのですが、うまくいきませんでした。
ご意見等、よろしくお願いします。
index.php(トップページ)
PHP
1<?php 2require_once('calender.php'); 3$cal = new Calender(); 4$cal->setTimeStamp(); 5$cal->query(); 6?> 7<!DOCTYPE html> 8<html> 9<title>カレンダー</title> 10<meta charset="utf-8"> 11<table border="1"> 12 <tr> 13 <th><a href="?ym=<?php echo $cal->h($cal->prev()); ?>">«</a></th> 14 <th colspan="5"><?php echo $cal->h($cal->yearManth()); ?></th> 15 <th><a href="?ym=<?php echo $cal->h($cal->next()); ?>">»</a></th> 16 </tr> 17 <thead> 18 <tr> 19 <th>日</th> 20 <th>月</th> 21 <th>火</th> 22 <th>水</th> 23 <th>木</th> 24 <th>金</th> 25 <th>土</th> 26 </tr> 27 </thead> 28 <tbody> 29 <?php 30 // $weeks 31 foreach ($cal->getWeeks() as $week) { 32 echo $week; 33 } 34 ?> 35 </tbody> 36</table> 37<form action="calender.php" method="POST"> 38<p>タイトル : <input type="text" name="title" size="20"></p> 39<p>日時 : <input type="date" name="task_date" min="2015-07-01"></p> 40<p>場所 : <input type="text" name="place" size="20"></p> 41<p>メモ : <textarea type="text" name="memo" rows="4" cols="40"></textarea></p> 42<input type="submit" value="追加する"> 43<input type="reset" value="リセット"> 44</form> 45</html>
detail.php(遷移先ページ)
PHP
1<?php 2require_once('calender.php'); 3$cal = new Calender(); 4$cal->edit(); 5?> 6<!DOCTYPE html> 7<html lang="ja"> 8<meta charset="utf-8"> 9<title>Today | タスク一覧</title> 10<h1>タスク一覧</h1> 11<p>タイトルをクリックすると編集できます。</p> 12<table border="1"> 13 <tr> 14 <td>日付</td> 15 <td><?php echo //ここに$_POST?? // ?></td> 16 <tr> 17 <td>タスク内容</td> 18 <td><?php echo //ここに$_POST?? // ?></td> 19 </tr> 20</table> 21<form action="index.php"> 22 <input type="submit" value="トップページへ戻る"> 23</form> 24</html>
calender.php(クラス)
PHP
1 <?php 2// dbconnect.php 3class dbconnect { 4 //mysqli の インスタンス化 、接続 5 public function ConnectDb() { 6 $this->mysqli = new mysqli('localhost', 'xxxxxx', 'xxxxxxx', 'xxxxxx'); 7 if ($this->mysqli->connect_error){ 8 die('Connect Error (' . $this->mysqli->connect_errno . ') '. $this->mysqli->connect_error); 9 exit; 10 } 11 } 12} 13class Calender extends dbconnect { 14 protected $weeks = array(); 15 protected $timeStamp; 16 // mysqli の メソッド 17 public function __construct(){ 18 $dbconnect = new dbconnect(); 19 if ($this->timeStamp === false) { 20 $this->timeStamp = time(); 21 } 22 // DB接続 23 parent::ConnectDb(); 24 } 25 26//省略 27 28 public function Create(){ 29 // タスクの配列を準備 30 $this->task = ""; 31 $taskData = array(); 32 // $pass = file_get_contents('edition.php'); 33 // PHP->MySQLtable 34 // タスクのパラメータを送れるようにする。 35 $view = $this->mysqli->query("SELECT * FROM tasks"); 36 // エラー処理 37 if (!$view) { 38 die('クエリーが失敗しました。'.mysql_error()); 39 } 40 while ($this->row = $view->fetch_assoc()) { 41 // 各メンバ取得 42 $id = $this->row['id']; 43 $title = $this->row['title']; 44 $task_date = $this->row['task_date']; 45 $place = $this->row['place']; 46 $memo = $this->row['memo']; 47 $this->task .= "<tr><td><a href='edition.php'>${title}</a></td><td>${task_date}</td><td>${place}</td><td>${memo}</td></tr>"; 48 } 49 50 } 51// 省略 52 public function edit() { 53 if (!empty($_POST)) { 54 if ($_POST['memo'] !=''); 55 $this->sql = sprintf('INSERT INTO tasks SET memo=%d', 56 mysql_real_escape_string($id['id']), 57 mysql_real_escape_string($_POST['memo']) 58 ); 59 mysqli_query($this->sql) or die(mysqli_error()); 60 61 header('Location : index.php'); 62 } 63 } 64 public function edit_do(){ 65 if (!isset($_POST['memo'])) { 66 !$errors[] = 'errors'; 67 } 68 $memo = $_POST['memo']; 69 $stmt = $this->mysqli->prepare("UPDATE tasks set memo = ? where memo = $memo;"); 70 $stmt->execute(array($_POST['memo'])); 71 } 72} 73 74 75?>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。