Page 1 of 1

Replace multiple fields in active record with one variable

Posted: Tue Apr 21, 2009 3:11 pm
by haveagophp
Hello

Not sure how to do this in php, but what I am trying to achieve is to replace several fields in a record with a single variable.

For example, if I had a table in my database (MySQL) and a table with fields price1, price2, price3, price4 etc and wanted to replace them with a value stored in newprice that has been entered into a field by me, how could I do that?

I see there is a command called INSERT but that adds a record to the table.

I have also found this command:

Code: Select all

UPDATE my_table SET `my_field` = replace(`my_field`, "old_text", "new_text")
So if this is the command:

1. How would I add additional fields?
2. How do I ensure that the correct record is updated?
3. How can I implement this process via a command button

I would either like to do this via a command button in php or a hyperlink, it makes no difference.

If you need more information please let me know and some guidance would be most advantageous.

Thank you

Re: Replace multiple fields in active record with one variable

Posted: Tue Apr 21, 2009 3:26 pm
by MasterBeta

Code: Select all

UPDATE my_table SET price_1=$value, price_2=$value, price_3=$value, price_4=$value WHERE id_column=id_value
Do a google search and you will find TONS on info on how to do this.

Re: Replace multiple fields in active record with one variable

Posted: Tue Apr 21, 2009 4:26 pm
by haveagophp
Thank you