更新
我有一个函数,它从搜索查询中提取关键字,并将相关结果返回给用户。我正在尝试更新关键字表中的count列,当搜索该关键字时,每个关键字的值都增加1。然而,我得到了:
"字段列表"中的未知列"0"
UPDATE
keywords
SET0
=数组WHEREid
='|'
我的搜索功能的一部分:
$query = $this->db->select('*')->from('keywords')->WHERE('keyword', $term)->get();
// array used to save individual strings to DB with their ranking & ids
$tempArray = array();
if($query->num_rows() > 0){
foreach($query->result() as $row){
$entry_ids = json_decode($row->entry_ids);
$initial_count = $row->count;
foreach($entry_ids as $id){
$item = explode("|", $id);
if(!$this->search_array($item[0], $tempArray)){
$search['count'] = $initial_count++;
$search['keyword'] = $term;
$search['id'] = $item[0];
$search['ranking'] = $item[1];
array_push($tempArray, $search);
$this->db->where('id', $id);
$this->db->update('keywords', $tempArray);
最后一个if似乎不正确。这就是我会做的:
if(!$this->search_array($item[0], $tempArray))
{
$updatedData = array(
"count" => $row->count + 1,
"keyword" => $term, //As I see it, this is unnecessary
"id" => $item[0],
"ranking" => $item[1]
);
//I suppose that count, keyword, id and rankings are columns name in your table named keywords
$this->db->where('keyword', $term);
$this->db->update('keywords', $updatedData);
}