dynamic use of switch?

angehodgson
08:24:10
I have a script that generates a HTML table using a couple of dropdowns(http://www.plus2net.com/forum/topic.php?topic_id=16)
When I get the second reload to work properly and populate the final HMTL table (which in the dd3 tutorial would be the third dropdown), I need to format some results differently than others. I have a field in the mySQL source table, which is either "red", "blue" or NULL.
Within the while loop that displays the final HTML table, is it possible to use a switch command to direct the row's formatting to a specific CSS string?
angehodgson
08-24-2010
Not sure if this is the *best* way to do this, but I worked out this version:

First off, I amended the mySQL table so that the records with NULL in the "colour" field have something there (I used the word 'black')

Back in the PHP script, just under the line starting the 'while' loop which generates the detail table in HTML, I included a statement declaring the variable $colswitch="ewc".$loop3['colour'];
And then in the echo line, used td class=$colswitch

Hope this helps anyone with similar issues.
smo1234
08-24-2010
What you are doing is fine but there is no need to keep the status of color in MySQL table. Better to use PHP. Inside the while loop you can use switch or if statement to format the row with different color.
The way you use CSS it is fine. Keeping the formating code to PHP side will help in future also when you want to change some existing data to different color format. Here you can avoid the updating MySQL table again.
Please Login to post your reply or start a new topic