【发布时间】:2017-09-01 17:04:46
【问题描述】:
我正在使用 Codeigniter 3、PHP 和 MySQL。
我正在尝试从 MySQL 数据库中选择一条记录,并根据结果运行更新查询。
If result = 0, update.
If result = 1, do nothing.
到目前为止我的代码是;
public function addData($itemId) {
$gDescription = 'test';
$gPreviewLink = 'test';
$gThumbnail = 'test';
$gPageCount = 'test';
$this->db->select('g_data');
$this->db->from('item');
$this->db->where('item_id', $itemId);
$query = $this->db->get();
$result = $query->result();
// var_dump($result) returns array(1) { [0]=> object(stdClass)#22 (1) { ["g_data"]=> string(1) "0" } }
$data = array(
'item_description' => $gDescription,
'item_preview_link' => $gPreviewLink,
'item_thumbnail' => $gThumbnail,
'item_pageCount' => $gPageCount,
'g_data' => '1',
'g_data_timestamp' => 'NOW()'
);
// if result = 0 update
if($result == '0') {
$this->db->where('item_id',$itemId);
$this->db->update('item', $data);
}
}
我的数据库中的数据不会更新有什么原因吗?我没有收到任何错误消息。
任何帮助将不胜感激。
【问题讨论】:
-
你实际上并没有在这里问过问题......
-
$result 是数字还是字符?顶部示例显示数字,但您 == 到字符“0”
标签: php mysql codeigniter