[SOLVED] Need help with loop
Posted: Sat Sep 04, 2004 9:12 pm
There must be a way to simplfy the code below using a loop of some sort. I'm certain there is such a way, but I can't for the life of me work it out. I'm fairly new to PHP and just took a 3 month hiatus from working with it. Now I'm rusty.
I tried several variations of the following with no luck:
What am I missing here?
Thanks in advance.
Code: Select all
<?php
$p1=$row["p1"];
if ($p1 < 1) {$p1 = "- ";}
if ($p1 == 999) {$p1 = "Gym";}
$p2=$row["p2"];
if ($p2 < 1) {$p2 = "- ";}
if ($p2 == 999) {$p2 = "Gym";}
$p3=$row["p3"];
if ($p3 < 1) {$p3 = "- ";}
if ($p3 == 999) {$p3 = "Gym";}
$p4=$row["p4"];
if ($p4 < 1) {$p4 = "- ";}
if ($p4 == 999) {$p4 = "Gym";}
$p5=$row["p5"];
if ($p5 < 1) {$p5 = "- ";}
if ($p5 == 999) {$p5 = "Gym";}
$p6=$row["p6"];
if ($p6 < 1) {$p6 = "- ";}
if ($p6 == 999) {$p6 = "Gym";}
$p7=$row["p7"];
if ($p7 < 1) {$p7 = "- ";}
if ($p7 == 999) {$p7 = "Gym";}
?>I tried several variations of the following with no luck:
Code: Select all
<?php
$roomCheck = array (0 => 'P0','P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7');
foreach ($roomCheck as $key => $value) {
if ($row["$value"] < 1) { $roomNumber = "- ";
} elseif ($row["$value"] == 999) { $roomNumber = "Gym";
} else { $roomNumber = $row["$value"];
}
echo '<td align="right">'. $roomNumber.'</td>';
}
?>Thanks in advance.