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 Quote 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>"; Quote 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 Quote 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. Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/209712-code-clean-up/#findComment-1095750 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.