I am having trouble with my table as I run it through the for loop. Currently I am getting the following output:
Room(s) Check-In Check-Out No. of Nights Rate Room1 04-09-2014 05-09-2014 1 $0 Room2 04-09-2014 05-09-2014 1 $0 Room3 04-09-2014 05-09-2014 1 $100.00 Room4 04-09-2014 05-09-2014 1 $100.00
What I want it to look like is this:
Room(s) Check-In Check-Out No. of Nights Rate Room3 04-09-2014 05-09-2014 1 $100.00 Room4 04-09-2014 05-09-2014 1 $100.00
The array looks like this:
Array
(
[1] => 0
[2] => 0
[3] => 100.00
[4] => 100.00
)
I want anything with an array value of 0 to be omitted but if I change the value of 'X' I get one too few or one too many rows.
The 0 values are generated from checkbox posts <input type="hidden" name="chk" value="0">
and not from the SQL statement.
I have tried: if ($_SESSION['r_id'][$x] != 0)
it gives:
Room(s) Check-In Check-Out No. of Nights Rate Room1 04-09-2014 05-09-2014 1 $100.00 <-- Should be Room3 Room2 04-09-2014 05-09-2014 1 $100.00 <-- Should be Room4
HTML/SQL/PHP:
<table width="500" border="0" align="center">
<tr>
<td>Room(s)</td>
<td>Check-In</td>
<td>Check-Out</td>
<td>No. of Nights</td>
<td>Rate</td>
</tr>
<tr>
<?
$sth = $dbh->prepare("SELECT * FROM room");
$sth->execute();
$result = $sth->fetchAll();
$y = 0;
for ($x=1; $x<=count($_SESSION['r_id']); $x++) {
?>
<tr>
<td>
<!-- Modal Content -->
<div id="r_id_<?=$y?>" class="reveal-modal">
<h1><?=$result[$y]['r_type'];?></h1>
<p><?=$result[$y]['r_desc'];?></p>
<h2>$<?=$result[$y]['r_rate'];?></h2>
<a class="close-reveal-modal">×</a>
</div><!-- Modal Content End -->
<!-- Modal Link -->
<a href="#" data-reveal-id="r_id_<?=$y?>"><?=$result[$y]['r_type'];?></a>
<!-- Modal Link End --></td>
<td><?=$_SESSION['checkin_date'];?></td>
<td><?=$_SESSION['checkout_date'];?></td>
<td><?=$_SESSION['no_nights'];?></td>
<td>$<?=$_SESSION['r_id'][$x];?></td>
</tr>
<?
$y++;
}
?>
</table>