ubh
03-03-2009, 02:44 AM
Hey I am trying to figure out a way to preform either an UPDATE or a INSERT INTO depending on if a row exists or not.
I am running an AJAX process that sends a series of elements inline CSS style values into my database.
Problem is that there should only be one row for each element and then its CSS values should be stored in the proceeding columns. What I get however, because my AJAX process runs in a for loop and loops over all elements, is multiple rows each containing that particular loops sent CSS style.
Looks like this:
|element_id|width|height|background-color|
------------------------------------------
|first |null |null |#000000 |
|first |null |100px |null |
|first |200px|null |null |
What I need is to somehow in my php file, try and run a UPDATE process first, and if no row exists then perform an INSERT INTO query.
Anyone know how to conditional a MySQL query like this??
I am running an AJAX process that sends a series of elements inline CSS style values into my database.
Problem is that there should only be one row for each element and then its CSS values should be stored in the proceeding columns. What I get however, because my AJAX process runs in a for loop and loops over all elements, is multiple rows each containing that particular loops sent CSS style.
Looks like this:
|element_id|width|height|background-color|
------------------------------------------
|first |null |null |#000000 |
|first |null |100px |null |
|first |200px|null |null |
What I need is to somehow in my php file, try and run a UPDATE process first, and if no row exists then perform an INSERT INTO query.
Anyone know how to conditional a MySQL query like this??