Jump to content

Code Clean Up


thecase

Recommended Posts

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

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

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.