Mysql
 sql >> Datenbank >  >> RDS >> Mysql

So deaktivieren Sie dynamische Auswahlfeldoptionen basierend auf Daten, die aus zwei Tabellen in der MySQL-Datenbank stammen

den Code ohne die verschachtelte Schleife neu schreiben

$date = '22-March-2014';

$taken_slots = array(); // resets the varaiable for each date
$bookings_qry = mysqli_query($con,"SELECT event_time_slot_id FROM tb_event_booking WHERE event_date=$date");
while($bookings_row = mysqli_fetch_assoc($bookings_qry)) $taken_slots[] = $bookings_row['event_time_slot_id'];
$slots_qry = mysqli_query($con,"SELECT * FROM tb_event_time_slots");
$calendar = '<select>'; // this will actually be concatinating from all other dates
$calendar .= '<option value="select" disabled="disabled">Select a Time</option>';
while($slots_row = mysqli_fetch_assoc($slots_qry)) {
    $slot_id = $slots_row['event_time_slot_id']
    $calendar .= '<option value="'.$slot_id.'" ';
    if(in_array($slot_id, $taken_slots)) $calendar .= 'disabled="disabled" ';
    $calendar .= '>'.$slots_row['event_time_slots'].'</option>';
}
$calendar .= '</select>';