webguync Posted April 21, 2010 Share Posted April 21, 2010 I have an on-line quiz application which submits answers into a MySQL DB. I have a field called 'incorrect_resp' which will display values such as 1,7,9,12. I want to be able to take those values and apply to static HTML to visually show a question answered incorrectly. So it would look like this. <div id="Questions"> <dl id="Q1" class="wrong"> <dt>Question 1</dt> <dd>A</dd> <dd>B</dd> <dd>C</dd> </dl> </div> in the CSS .wrong{background-color:#e6fa08} so basically I need help using PHP to determine how to pull the values from the MySQL table and set a CSS class to equal those values and then assign to the proper questions. Let me know if I need to clarify anything. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/199312-setting-a-css-class-based-on-values-in-mysql-field/ Share on other sites More sharing options...
AdRock Posted April 21, 2010 Share Posted April 21, 2010 I presume you would have the class details stored in the database such as "wrong" with all the style information? Link to comment https://forums.phpfreaks.com/topic/199312-setting-a-css-class-based-on-values-in-mysql-field/#findComment-1046116 Share on other sites More sharing options...
webguync Posted April 22, 2010 Author Share Posted April 22, 2010 no, but if I need to do it that way I can. Please elaborate on that method. Link to comment https://forums.phpfreaks.com/topic/199312-setting-a-css-class-based-on-values-in-mysql-field/#findComment-1046196 Share on other sites More sharing options...
webguync Posted April 23, 2010 Author Share Posted April 23, 2010 Hi, with this I am already pulling out the values in my field ['incorrect_resp'] and printing out into a table td. I just need to take those values and convert to something like this. $wrong = array(1, 4, 3, 10); foreach($answers as $key => $value){ if (in_array($key, $wrong)){ $class = "wrong"; } else { $class="correct"; } echo "<td class=\"$class\">$value</a>"; } how would I get the values from ['incorrect_resp'] into my $wrong variable? Link to comment https://forums.phpfreaks.com/topic/199312-setting-a-css-class-based-on-values-in-mysql-field/#findComment-1047242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.