CodeIgniter Forums

Full Version: if exist update data else insert new data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a table with images. The user can update the existing images or add new. After he can save and send all data with POST. I would like update the data for existing images and insert new rows if the images doesn't exist. What is the correct query for to do this in Codeigniter 4?

Thanks for the support.
Try to fetch the image if it does not exist then an empty array will be returned.

Now you can use and if statement to check the returned array,
if empty insert image else update image.
(05-14-2020, 04:25 AM)InsiteFX Wrote: [ -> ]Try to fetch the image if it does not exist then an empty array will be returned.

Now you can use and if statement to check the returned array,
if empty insert image else update image.

Thanks for your answer. If i have 5 images: 3 updated and 2 new...with a if statement i can update 3 images OR add 2 new images. Have i lost something in your answer?  Undecided