1
Codeigniter 3, PHP 및 MySQL을 사용하고 있습니다.Codeigniter Select (조건부) 업데이트 쿼리
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);
}
}
데이터가 데이터베이스에서 업데이트되지 않는 이유가 있습니까? 오류 메시지가 표시되지 않습니다.
도움을 주시면 감사하겠습니다.
실제로 여기에 질문하지 않았습니다 ... –
은 $ 결과 숫자입니까? 위 예제는 숫자를 보여 주지만 여러분은 ==를 문자 '0' – xQbert