thecase Posted August 3, 2010 Share Posted August 3, 2010 Hi, Here is a tiny bit of my code $r = mysql_query ($query); while ($row = mysql_fetch_array ($r, MYSQL_ASSOC)) { echo "<tr> <td align=\"center\">"; echo date("M-d-Y", mktime(0, 0, 0, $row['month'], $row['day'], $row['year'])); echo "</td> "; if ($row['presenter1status'] == '0') { echo "<td align=\"center\"><font color=\"#FF9900\">{$row['presenter1']}</font></td>"; } elseif ($row['presenter1status'] == '1') { echo "<td align=\"center\"><font color=\"green\">{$row['presenter1']}</font></td>"; } elseif ($row['presenter1status'] == '2') { echo "<td align=\"center\"><font color=\"red\">{$row['presenter1']}</font></td>"; } if ($row['presenter2status'] == '0') { echo "<td align=\"center\"><font color=\"#FF9900\">{$row['presenter2']}</font></td>"; } elseif ($row['presenter2status'] == '1') { echo "<td align=\"center\"><font color=\"green\">{$row['presenter2']}</font></td>"; } elseif ($row['presenter2status'] == '2') { echo "<td align=\"center\"><font color=\"red\">{$row['presenter2']}</font></td>"; } if ($row['engineerstatus'] == '0') { echo "<td align=\"center\"><font color=\"#FF9900\">{$row['engineer']}</font></td>"; } elseif ($row['engineerstatus'] == '1') { echo "<td align=\"center\"><font color=\"green\">{$row['engineer']}</font></td>"; } elseif ($row['engineerstatus'] == '2') { echo "<td align=\"center\"><font color=\"red\">{$row['engineer']}</font></td>"; } echo "</tr> I was wondering if there is a better way of doing this as I think including this many ifesle statements in a while loop that could go round about 40 times might be very heavy on the resources. Thanks Link to comment https://forums.phpfreaks.com/topic/209712-code-clean-up/ Share on other sites More sharing options...
AbraCadaver Posted August 3, 2010 Share Posted August 3, 2010 Something like this maybe: $colors = array("#FF9900", "green", "red"); echo "<td align=\"center\"><font color=\"{$colors[$row['presenter1status']]}\">{$row['presenter1']}</font></td>"; echo "<td align=\"center\"><font color=\"{$colors[$row['presenter2status']]}\">{$row['presenter2']}</font></td>"; echo "<td align=\"center\"><font color=\"{$colors[$row['engineerstatus']]}\">{$row['engineer']}</font></td>"; Link to comment https://forums.phpfreaks.com/topic/209712-code-clean-up/#findComment-1094781 Share on other sites More sharing options...
thecase Posted August 3, 2010 Author Share Posted August 3, 2010 Great. Thanks Link to comment https://forums.phpfreaks.com/topic/209712-code-clean-up/#findComment-1094785 Share on other sites More sharing options...
Psycho Posted August 3, 2010 Share Posted August 3, 2010 Be sure to define the array before the loop instead of defning it within the loop. No need to define it 40 times. Link to comment https://forums.phpfreaks.com/topic/209712-code-clean-up/#findComment-1094842 Share on other sites More sharing options...
thecase Posted August 5, 2010 Author Share Posted August 5, 2010 Be sure to define the array before the loop instead of defning it within the loop. No need to define it 40 times. I actually did this. Thanks for the tip Link to comment https://forums.phpfreaks.com/topic/209712-code-clean-up/#findComment-1095750 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.