I'm building a page in which i need to list in an html table the various values that I have in a database for about 60 rows.
I want to change the color of a certain td (cell) in my table depending of the value that return one of my type of variables (variable party_1 to party_60)
Whay I have done yet is this (I only show here the first 2 rows but it's the same principle for the 60)
<table id="example" class="table-bordered table-striped table-condensed">
<thead>
<tr>
<th class="both" data-field="Political party" data-sortable="true">Political Party</th>
<th class="both" data-field="Gender" data-sortable="true">Gender</th>
<th class="both" data-field="Name" data-sortable="true">Name</th>
<th class="both" data-field="Date of birth" data-sortable="true">DOB</th>
<th class="both" data-field="Profession" data-sortable="true">Profession</th>
</tr>
</thead>
<tbody>
<?php if (!empty($name_1)){ ?>
<tr>
<td <?php if (($parti_1 == "MDM") || ($parti_1 == "UC") || ($parti_1 == "DIV")) { echo 'style="background-color:gray;"';}
else if (($parti_1 == "UG") || ($parti_1 == "SOC") || ($parti_1 == "DVG") || ($parti_1 == "PG")) { echo 'style="background-color:#FD6C9E;"';}
else if (($parti_1 == "FG") || ($parti_1 == "COM") || ($parti_1 == "EXG")) { echo 'style="background-color:red;"';}
else if (($parti_1 == "FN") || ($parti_1 == "EXD")) { echo 'style="background-color:#334185;"';}
else if (($parti_1 == "UMP") || ($parti_1 == "DVD") || ($parti_1 == "UD") || ($parti_1 == "UDI")) { echo 'style="background-color:blue;"';}
else if (($parti_1 == "VEC")) { echo 'style="background-color:green;"';}
?>>
<?php echo $parti_1;?>
</td>
<td><?php echo $gender_1;?></td>
<td><?php echo $name_1;?></td>
<td><?php echo convert_to_french_date($birth_1);?></td>
<td><?php echo $profession_1;?></td>
</tr>
<?php }?>
<?php if (!empty($name_2)){ ?>
<tr>
<td <?php if (($parti_2 == "MDM") || ($parti_2 == "UC") || ($parti_2 == "DIV")) { echo 'style="background-color:gray;"';}
else if (($parti_2 == "UG") || ($parti_2 == "SOC") || ($parti_2 == "DVG") || ($parti_2 == "PG")) { echo 'style="background-color:#FD6C9E;"';}
else if (($parti_2 == "FG") || ($parti_2 == "COM") || ($parti_2 == "EXG")) { echo 'style="background-color:red;"';}
else if (($parti_2 == "FN") || ($parti_2 == "EXD")) { echo 'style="background-color:#334185;"';}
else if (($parti_2 == "UMP") || ($parti_2 == "DVD") || ($parti_2 == "UD") || ($parti_2 == "UDI")) { echo 'style="background-color:blue;"';}
else if (($parti_2 == "VEC")) { echo 'style="background-color:green;"';}
?>>
<?php echo $parti_2;?>
</td>
<td><?php echo $gender_2;?></td>
<td><?php echo $name_2;?></td>
<td><?php echo convert_to_french_date($birth_2);?></td>
<td><?php echo $profession_2;?></td>
</tr>
<?php }?>
etc...
I have more that 60 variables of the type party_XX so I think there might be a better / clever /lighter solution not to do 60 times this if / else if statement.
Thanks for your help on that purpose.
Best Regards.
Aucun commentaire:
Enregistrer un commentaire