I'm having a problem with a hard coded array I'm using to test. I'm looping some html and php to create a header list for each top level item, which works. But I'm looping again to create a modal for each item and it's only corresponding to the first item.
Here's the array, as it's hard-coded:
<?php
$displays = array(
"Company" => array(
"Company One Main"=>array(
"Displays"=>array(
"Room One"=>array(
"Page"=>array(
"Type"=>"News",
"Expiration"=>"06/12/2018"),
),
"Room Two"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
"Room Three"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
),
),
"Company One Other"=>array(
"Displays"=>array(
"Room Two"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
"Room Three"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
),
),
"Company Two Main"=>array(
"Displays"=>array(
"Room One"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
"Room Two"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
),
),
"Company Two Other"=>array(
"Displays"=>array(
"Room One"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
"Room Two"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
"Room Three"=>array(
"Page"=>array(
"Type"=>"Social",
"Expiration"=>"06/18/2018"),
),
),
),
),
);
?>
So my first bit of code works correctly by creating a list of the 4 areas, like so:
The problem is, when I click edit for any of the four companies, it shows the modal containing only the info for the first element in the array, Company One Main. The layout is right but it only shows the rooms, page types and expirations for that first company rather than each list item having a modal for it's own respective info.
So no matter which one I click on I see this:
I may just be looping incorrectly. Here's the PHP and HTML
/*These first two lines are correct, they created the list of areas with 'edit' links*/
<?php foreach($displays["Company"] as $area_name => $area_details): ?>
<h6><?php echo $area_name ?><a href="#" data-toggle="modal" data-target="#expiringDisplays">Edit</a></h6>
<!-- Modal -->
<div class="modal fade" id="expiringDisplays" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<?php foreach($area_details["Displays"] as $d=>$v): ?>
<h5 class="modal-title" id="modalLabel"><?php echo $area_name . " - " . $d?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<!-- END MODAL HEADER -->
</div>
<div class="modal-body">
<?php foreach($v as $k=>$n): ?>
<!--Body of the Modal for expired displays-->
<br>
<h6><?php echo $n['Type'] ?></h6>
<h6>Date/Time Expiring: <?php echo $n["Expiration"] ?></h6>
<h6>Set New Expiration:</h6>
<a href="#" style="float:left;">View Display</a>
<br>
<hr>
<?php endforeach; ?>
<?php endforeach; ?>
<!-- END MODAL BODY -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
<!-- END MODAL FOOTER -->
</div>
<!-- END MODAL CONTENT -->
</div>
<!-- END MODAL DIALOGUE -->
</div>
<!-- END MODAL -->
</div>
<?php endforeach; ?>