Я пытаюсь структурировать свой foreach l oop для цикла, хотя все даты в моих массивах отметок времени, чтобы я мог отображать результаты в 5 отдельных таблицах для каждой из дат
Это моя функция чтобы получить информацию из базы данных
$users_site = "London";
$timeStampFrom = ( [0] => 1596655740 [1] => 1596745740 [2] => 1596828540 [3] => 1597087740 [4] => 1597177800 );
$timeStampTo = ( [0] => 1596659340 [1] => 1596749340 [2] => 1596832140 [3] => 1597095000 [4] => 1597181400 );
function show_available_equipment($users_site, $timeStampFrom, $timeStampTo){
// defines db from instialize page as a global variable
foreach ($timeStampFrom as $timeStampStart=>$timeStampTo) {
global $db;
//SQL statement to query the database for available gear
$sql= "SELECT av_inventory.ID AS equipID, av_equipment_type.equipment, "
. "av_inventory.product, av_inventory.serial, av_inventory.current_location, "
. "av_inventory.site, av_inventory.status, av_products.product, av_buildings.building FROM av_inventory JOIN "
. "av_equipment_type ON av_inventory.equipment =av_equipment_type.ID "
. "JOIN av_products ON av_inventory.product = av_products.ID JOIN "
. "av_buildings ON av_inventory.current_location = av_buildings.ID WHERE "
. "av_inventory.site =? AND av_inventory.ID NOT IN (SELECT av_bookings.av_inventory_id FROM "
. "av_bookings WHERE date_time_from <= ? and date_time_to >= ?) GROUP BY av_inventory.ID;";
// prepares our sql statement
$stmt = mysqli_stmt_init($db);
//if there is a SQL error exit
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: book_gear.php?error=sqlerror123");
exit();
}
// otherwise go ahead
else {
/* binding those variables to the question marks in SQl statement
* above variables need to be prepared and binded like this in php
* and cannot just be inserted into statements
*/
mysqli_stmt_bind_param($stmt, "sss", $users_site, $timeStampStart, $timeStampTo);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
return $result;
}}}
Здесь я пытаюсь отобразить информацию на основе 5 указанных дат. Один стол на каждый день. На данный момент я получаю информацию только за первый день, что заставляет меня думать, что моя функция l oop неверна.
<?php $equipments[] = book_equip_idle($users_site, $timeStampFrom, $timeStampTo); ?>
<?php foreach ($equipments as $equipment) { ;?>
<table id="schedule_table_new" class="schedule_list">
<tr>
<caption class="sched_label">Event Name</caption>
<th onclick="sortTable(0)">Equipment Type</th>
<th onclick="sortTable(1)">Product No.</th>
<th onclick="sortTable(2)">Serial No.</th>
<th onclick="sortTable(3)">Current Location</th>
<th onclick="sortTable(5)">Book Item</th>
</tr>
<br/><br/>
<?php
while ($av_inventory = mysqli_fetch_assoc($equipment)) { ?>
<tr>
<td><?php echo h($av_inventory['equipment']); ?></td>
<td><?php echo h($av_inventory['product']); ?></td>
<td><?php echo h($av_inventory['serial']); ?></td>
<td><?php echo h($av_inventory['building']); ?></td>
<!--Checkbox sends two pieces of data equipment name to events SQL
table and serial number to bookings SQL table -->
<td><input name='event[<?php echo $key ;?>][equipment][]' type='checkbox' value="<?php echo $av_inventory['equipID'];?>"></td>
</tr>
<?php } } ?>
</table>