Mysql
 sql >> Base de données >  >> RDS >> Mysql

Comment désactiver les options de zone de sélection dynamique basées sur les données provenant de deux tables dans la base de données mysql

réécrire le code sans la boucle imbriquée

$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>';