Jump to content

setting a css class based on values in MySQL field


webguync

Recommended Posts

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!

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.