Replace multiple fields in active record with one variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
haveagophp
Forum Newbie
Posts: 2
Joined: Tue Apr 21, 2009 3:07 pm

Replace multiple fields in active record with one variable

Post 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
MasterBeta
Forum Commoner
Posts: 38
Joined: Thu Apr 02, 2009 4:35 am
Location: Lincoln, NE

Re: Replace multiple fields in active record with one variable

Post 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.
haveagophp
Forum Newbie
Posts: 2
Joined: Tue Apr 21, 2009 3:07 pm

Re: Replace multiple fields in active record with one variable

Post by haveagophp »

Thank you
Post Reply