【发布时间】:2015-04-22 05:01:48
【问题描述】:
伙计们,请在下面查看我的代码。我真的不知道如何运行我的查询。我想要实现的是我将首先在我的数据库中搜索尚未完成或取消的数据,然后返回的数据将被更新为“否”。 我正确运行了第一个查询,即搜索。但我不知道如何制作第二个。请帮忙。谢谢。
<?php
require 'connection.php';
class updateOverdue{
private $db,$sql,$stmt,$row;
public function __construct(){
$this->db = new connection();
$this->db = $this->db->dbConnect();
}
public function updatefields(){
$this->sql = "SELECT * FROM jrf_tbl WHERE status <> 'Finished' AND status <> 'Cancelled'";
$this->stmt = $this->db->prepare($this->sql);
$this->stmt->execute();
if($this->stmt->rowCount()){
while($this->row = $this->stmt->fetch(PDO::FETCH_OBJ)){
echo "
<tbody>
<tr>
<td>",$TEST= $this->row->ID, "</td>
<td>",$this->row->strjrfnum, "</td>
<td>",$this->row->strstatus,"</td>
<td>",$this->row->strpriority,"</td>
<td>",$this->row->strdate,"</td>
<td>",$this->row->strduedate,"</td>
</tr>
</tbody>";
}
};
foreach ($TEST as $value) { /* here is my question */
$this->sql = "UPDATE jrf_tbl SET strifoverdue ='no' WHERE ID=". $value;
$this->stmt = $this->db->prepare($this->sql);
$this->stmt->execute();
}
}
}//End Class
?>
<table border=1>
<thead>
<tr>
<th>ID</th>
<th>JRF Num</th>
<th>Status</th>
<th>Priority</th>
<th>Date received</th>
<th>Due Date</th>
</tr>
</thead>
<?php
$OverDue = new updateOverdue();
$OverDue->updatefields();
?>
</table>
【问题讨论】: