Jump to content

If data exists already update, otherwise insert


Kingskin

Recommended Posts

Using MySQL & PHP, how can I first, check if a row with a given primary id exists and if so, update it, or if not insert it. Secondly, if data already exists in a given field, I want to append the new data onto it rather than overwrite it.

To clarify a bit, if I have 2 columns: id & value

I want to check if id (primary key) exists in the table.

If it doesn't exist, I want to insert a row with that 'id', and some data into 'values', such as '2 3 7 87'

If it [i]does[/i] exist, i want to update the row with that id, the append some data to whats already in the 'value' field, so if the 'value' field already contains the data '2 3 7 87' and i also want to add '13 5 9', i end up with '2 3 7 87 13 5 9' in that column.

Thanks for any help you can give me :)


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.