webguync Posted August 7, 2008 Share Posted August 7, 2008 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! Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted August 7, 2008 Share Posted August 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
webguync Posted August 7, 2008 Author Share Posted August 7, 2008 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> Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted August 7, 2008 Share Posted August 7, 2008 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 Quote Link to comment Share on other sites More sharing options...
webguync Posted August 8, 2008 Author Share Posted August 8, 2008 can you do the changing classes with 7 different classes though? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.