Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

PHP
$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
Posted
Updated 28-Nov-19 1:13am

1 solution

provide your model code also what you are using in count_all function ?

Simply what you can do you check if the value exist in database something like this.
PHP
$query = $this->db->get_where('table_name',array('ad_code'=>$code,'ad_image'=>$image_link));


Check if $query->num_rows() > 0 ,if yes update else insert.

Feel free to let me know if you have any difficulty understanding it.

Regards,
Zeeshan.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900