今回はPHPでMySQLのカラムやレコードを『追加・編集・削除』させたいと思います。
以前、https://teratail.com/questions/13285 でも同じような質問をさせていただいたのですが、自分なりに解釈するのが難しく、どういった記述をしていくのか考え方が分からなくなった為、質問させていただきます。
まず、HTMLのテーブルタグで「日付」タブと「タスク内容」タブを作成しています。
HTML
1<p>タイトルをクリックすると編集できます。</p> 2<table border="1"> 3 <tr> 4 <td>日付</td> 5 <td> 6 <?php 7 if(isset($_GET['task_date'])){ 8 echo $cal->h($_GET['task_date']); 9 } 10 ?> 11 </td> 12 <tr> 13 <td>タスク内容</td> 14 <td> 15 <?php 16 if(isset($_GET['memo'])){ 17 echo $cal->h($_GET['memo']); 18 } 19 ?> 20 </td> 21 </tr> 22</table>
task_dateとmemoは各カラムになります。
やりたいこと
→ここにDBの内容を表示して、編集・削除ができるようになる。
やりかた
1.task というクラスでメソッドを作成する。
2 .task_doというクラスで引数を作成する。
実際に、やろうと書いてみるものの、上の画像のように、まずDBのデータ自体が表示されていない現状です。
HTML内にechoしていることも含め、アドバイスお願いします。
PHP
1class task extends Calender { 2 // メソッドを作成 3 protected $stmt; 4 protected $create = ""; 5 protected $enter; 6 7 public function __construct() { 8 parent::__construct(); 9 $this->stmt = $this->mysqli; 10 $this->enter = $stmt->extends; 11 } 12 public function setSQL() { 13 return $this->stmt; 14 } 15 public function create() { 16 return $this->create; 17 } 18 public function Enter() { 19 return $this->enter; 20 } 21} 22class task_do extends task { 23 // 引数を作成 24 protected $insert; 25 protected $update; 26 protected $delete; 27 28 public function __construct() { 29 parent::__construct(); 30 $this->insert = $this->stmt->prepare("INSERT INTO tasks (id,title,task_date,place,memo) VALUES (?,?,sysdate(),?,?)"); 31 $this->update = $this->stmt->prepare("DELETE FROM tasks where task_date = ?"); 32 $this->delete = $this->stmt->prepare("UPDATE tasks set title = ? where id = '$id';"); 33 } 34 public function inSert() { 35 $this->create = "INSERT INTO tasks VALUES (NULL,'Stuttgart','DEU','Stuttagart',617000)"; 36 $this->stmt->query($this->create); 37 $this->enter; 38 } 39 public function upDate() { 40 $this->upDate; 41 $this->enter; 42 } 43 public function deLete() { 44 $this->deLete; 45 $this->enter; 46 } 47} 48 49 50?>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。