Jump to content

assigning CSS to different MySQL column values


webguync

Recommended Posts

Hello,

 

I have a MySQL table with one column named 'District'. If I give that column different values such as 1,2,3,4,5 and then in my HTML output have something like <td><?php echo $employeeResults[$c][$i]['district'];?></td>, how could I assign a different CSS class to each individual value in that column? example if the value is 1, .blue, 2 .green, 3.red etc.

 

hope I am making sense and get get some assistance!

Link to comment
Share on other sites

If you were going to use say classes on the td, you could do something like:

 

<td class="<?php if($row['value_you_are_placing_in_cell'] == 1) { echo "class1"; } else { echo "standard" } ?>"></td>

 

Or something to that effect

Link to comment
Share on other sites

thanks so I would need to do that for each value? example I may have 7 values

 


<td class="<?php if($row['value_you_are_placing_in_cell'] == 1) { echo "class1"; } else { echo "standard" } ?>"></td>
<td class="<?php if($row['value_you_are_placing_in_cell'] == 2) { echo "class1"; } else { echo "standard" } ?>"></td>
<td class="<?php if($row['value_you_are_placing_in_cell'] == 3) { echo "class1"; } else { echo "standard" } ?>"></td>
<td class="<?php if($row['value_you_are_placing_in_cell'] == 4) { echo "class1"; } else { echo "standard" } ?>"></td>
<td class="<?php if($row['value_you_are_placing_in_cell'] == 5) { echo "class1"; } else { echo "standard" } ?>"></td>
<td class="<?php if($row['value_you_are_placing_in_cell'] == 6) { echo "class1"; } else { echo "standard" } ?>"></td>
<td class="<?php if($row['value_you_are_placing_in_cell'] == 7) { echo "class1"; } else { echo "standard" } ?>"></td>

 

 

Link to comment
Share on other sites

and if you want to do changeing class then you can use this

while(something)
{
    // alternate class
    $class = ($i%2 == 0) ? 'one class' : ' 2 class;

// Print out the contents of each row into a table
echo "<tr class='".$class."'>";

    $i++; // increment counter

And all that would do is;

use class 1

then class 2

then class 1

then class 2

and so on

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.