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!

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

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>

 

 

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

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.