Kingskin Posted March 28, 2006 Share Posted March 28, 2006 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 & valueI 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 :) Quote Link to comment Share on other sites More sharing options...
fenway Posted March 28, 2006 Share Posted March 28, 2006 Recent versions of MySQL support INSERT... ON DUPLICATE KEY UPDATE... statements, which for certain cases, is preferable to a REPLACE statement. Check the refman for the appropriate syntax. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.