Jump to content

Code Clean Up


thecase
 Share

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
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
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.