Click here to Skip to main content
15,799,017 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


               $this->session->set_flashdata('message', 'adds updated in database');
               redirect(current_url(), 'refresh');
               $this->session->set_flashdata('message', 'adds inserted in database');
               redirect(current_url(), 'refresh');

note that the table has only one raw any help
Updated 28-Nov-19 2: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.
$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.

Share this answer

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