sql >> Base de Datos >  >> RDS >> Mysql

Cómo deshabilitar las opciones del cuadro de selección dinámico en función de los datos que provienen de dos tablas en la base de datos mysql

reescriba el código sin el bucle anidado

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