I am trying to print some information within a foreach loop:
<?php foreach($output['data']['rooms'] as $info): ?>
<?php if($info['room_number'] == $id): ?>
<h1 style="font-size: 20pt; color: white;">Room: <?php echo $info['room_number']; ?></h1>
<?php echo '<a style="float: right;" class="button1" href="'.$curIndex.'">Home</a>'; ?>
<hr style="margin-top: 20px;">
<?php $services = reset($info['services']); ?>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Charges: <?php echo ($services['room_charges']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Adult: <?php echo ($services['adult']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?> </h2>
<h2 style="font-size: 14pt; color: #924c9e;"> Room Status: <?php echo $info['status']; ?></h2>
<?php else : echo "No data found for the room number you entered."; ?>
<?php endif; ?>
<?php endforeach; ?>
The part that is NOT working correctly is the <?php else: "no data found for the room number you entered."; ?>
The else statement echo's that information for every entry within the foreach
loop, rather than just one time. Easiest way of explaining what i'm trying to do:
if room_number
matches the id
the user enters, then print everything that corresponds to that room number, else print that room's data was not found. If room number not found, I only want "No data found for the room number you entered"
to display one time on the page.
I can give you more code if you need it, but I think this should cover it. I just haven't been able to correctly include the else
within the foreach
loop.
Thank you for your help! I'll be sure to mark your answer correct if you can help me figure it out.