This seems like something that should be simple, and there's probably an obvious step I'm missing, but I'm stumped 😕 What I'm trying to do is create bookings for lab equipment stations with something like this:
$query = "INSERT INTO slotTest(courseID,weekID,dayID,timeID,stationID,expID,open) VALUES (";
foreach ($station as $stationID) {
foreach ($exp as $expID) {
foreach ($time as $timeID) {
$query .= "$course,$week,$dayID,$timeID,$stationID,$expID,1)";
$query .= ",(";
}
}
}
$query = substr($query, 0, -2); // strips the last ,( characters
$query .= ";";
The $station, $exp, and $time arrays all consist of values from a form on the previous page (with $station being the array of station IDs, $exp being the experiment IDs assigned to open stations, and $time being the time periods during which the stations are open. I think you can see the problem - if I had two time slots open for two stations, the total bookings should be four...instead, it winds up being 8 with the code above.
Ideally, there should only be one foreach statement for $time, but how do I give it the $stationID and $expID? In plain English, what should be happening is this:
"For every open time slot, insert the stationID and experimentID associated with that time slot."
There must be a more straightforward way of doing this, so I'd definitely appreciate any tips (especially if there's some other PHP function or method that could do what I want, but that I just don't know about yet...)