I’m trying to make that when the value of a MYSQL attribute is changed, other values ââof other attributes also vary.
For example:
I have the color_scheme attribute with value “RED”.
If the color_scheme value changes to “BLUE” the value of:
menu_color changes to #30618F
font_color changes to #FFFFFF
footer_color changes to #1A92CA
Is it possible?
And it must update the values only once, because users must be able to change specific atributes (like menu_color, font_color, footer_color) separately.
Just like this:
Try this:
How does this work? First you create a table with the colors (e.g. ‘color_scheme’). Then you get the values (e.g. ‘blue’,’#….’,…) from this table inserted into your ‘user_interface’ table. BTW I made the assumption that you will use this for a user interface. Anyway you can adopted it for your needs. Important to note is that you can only update data that is first inserted into a database. So, you should start with default colors when a user is added. I would even recommend that you create a separate table with the colors, separate from the user table.
Next you want to update the default colors based on the selected color scheme. Lets say you want to use ‘blue’. Then you should use an update query to update the values in the user_interface table (or colors table). The most basic way would be to do subqueries like I did with then says WHERE color_esquema = ‘blue’. I added the set color_name variable to ease the entries. With this statement you started to declare a variable called color_name and you just need to declare it once a use it throughout you query. You can if you want to revert back insert your color_esquema name.
SQL FIDDLE DEMO
I first add grey colors to the last row in the user_interface. Then I use the update query to change the value into a new color schema which is black. To break it down into steps.
First step
Then the same data with the update. B.T.W. fiddle doesn’t allow me to do this in right
panel. See final at the top.
Second step
PHP
A PHP script to change the color scheme.
This will only load the color scheme names:
You can use a CASE statement for this. This is a pretty simplified version, but this should get you on the right track.
You should make a
color_schemes
table and store the details for each color scheme there.Radical,
I’m Artur’s friend, I tried a different aproach for this same problem yesterday, and I don’t know if it’s easier or what… Please take a look at my other question
We are using WordPress, and we are not very good at coding PHP, we can adapt scripts and stuff, but we are not very good at creating our own.
Thank you for your efforts, we are almost there!