检查表codeigniter中是否存在某个值 [英] check if certain value exist in table codeigniter
问题描述
我有这样的表
注意id是自动增量
和函数没有使用传递id来检查它所以我需要检查ad_code和ad_image的值而不使用ID
____________________________________________________
id type ad_code ad_image
______________________________________________________
i想要检查ad_code值是否存在更新它否则插入它也如果ad_image存在更新它插入它
i尝试
$ data [' type'] = $ type;
$ data [' ad_image'] = $ image_link;
$ data [' ad_code'] = $ code;
if($ this-> site_adds_model-> count_all()> 0)
{
$ this-> site_adds_model-> update_by($ data);
$ this-> session-> set_flashdata(' message',' 在数据库'中添加更新);
redirect(current_url(),' refresh');
}
其他
{
$ this-> site_adds_model-> insert($ data);
$ this-> session-> set_flashdata(' message',' 添加插入数据库');
redirect(current_url(),' refresh');
}
请注意表中只有一个原始任何帮助
数据[' type'] =
type;
data [' ad_image 跨度>] =
i have table like that
note that id is auto increament
and the function not using passing id to check it so i need to check the value of ad_code and ad_image without using id
____________________________________________________
id type ad_code ad_image
______________________________________________________
i want to check if ad_code value exist update it else insert it also if ad_image exist update it else insert it
i tried
$data['type']=$type;
$data['ad_image']=$image_link;
$data['ad_code']=$code;
if($this->site_adds_model->count_all()>0)
{
$this->site_adds_model->update_by($data);
$this->session->set_flashdata('message', 'adds updated in database');
redirect(current_url(), 'refresh');
}
else
{
$this->site_adds_model->insert($data);
$this->session->set_flashdata('message', 'adds inserted in database');
redirect(current_url(), 'refresh');
}
note that the table has only one raw any help
data['type']=
type;
data['ad_image']=
这篇关于检查表codeigniter中是否存在某个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!