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!

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.