Agenda appuntamenti con più utenti
-
Buongiorno a tutti,
sono fermo a un punto dove non riesco a risolvero e avrei bisogno del vostro supporto.
Ho una tabella Appuntamenti composta da un id, data appuntamento, ora inizio, ora fine e utente interessato.
Nella tabella Appuntamenti concorrono più utenti.
Vorrei fare una query dove mi restituisce solo gli orari che sono occupati da tutti gli utenti contemporaneamente
Esempio:
oggi 02/11/2017 dalle ore 11:00 alle 12:00 tutti gli utenti interessato hanno un'appuntamento quindi la risposta vorrei che fosse full
oggi 03/11/2017 dalle ore 11:00 alle 12:00 solo due utenti interessati hanno un'appuntamento quindi la risposta vorrei che fosse freeHO provato a fare una query, ma mi da come risposta full anche se solo un utente ha l'ora occupata nonostante gli altri utenti siano liberi.
$query= "SELECT * FROM utenti"; $Recordset = mysql_query($query, $mcl) or die(mysql_error()); while($row=mysql_fetch_row($Recordset)) { $id_utente_abilitato=$row[0]; $query_a= "SELECT * FROM appuntamento where giorno_app='$data_appu' and ora_inizio<='$ora_cont' and ora_fine>='$ora_cont' and id_utente='$id_utente_abilitato'"; $Recordset_a = mysql_query($query_a, $mcl) or die(mysql_error()); while($row_a=mysql_fetch_row($Recordset)) { $id_libero=$row_a[0]; }}Grazie e ciao a tutti

-
Ciao leslie2016
credo che il problema sia come hai strutturato le query. In questo tuo modo se l'ultimo utente della lista ha un'appuntamento il risultato sarà true di sicuro. Prova così: in questo modo con il break dovrebbe uscire se un utente non ha appuntamenti.[COLOR=#0000BB][FONT=monospace]$query[/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"SELECT * FROM utenti"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$Recordset [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]mysql_query[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$mcl[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) or die([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]mysql_error[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()); while([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$row[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]mysql_fetch_row[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$Recordset[/FONT][/COLOR][COLOR=#007700][FONT=monospace])) { [/FONT][/COLOR][FONT=monospace][COLOR=#007700] [/COLOR][/FONT][COLOR=#0000BB][FONT=monospace]$id_utente_abilitato[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$row[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace] $query_a[/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"SELECT * FROM appuntamento where giorno_app='[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$data_appu[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]' and ora_inizio<='[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$ora_cont[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]' and ora_fine>='[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$ora_cont[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]' and id_utente='[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$id_utente_abilitato[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace] $Recordset_a [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]mysql_query[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$query_a[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$mcl[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) or die([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]mysql_error[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()); $entrato = false; while([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$row_a[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]mysql_fetch_row[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$Recordset[/FONT][/COLOR][COLOR=#007700][FONT=monospace])) { $entrato = true; [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$id_libero[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$row_a[/FONT][/COLOR][COLOR=#007700][FONT=monospace][[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]0[/FONT][/COLOR][COLOR=#007700][FONT=monospace]]; } if($entrato==false) break; } [/FONT][/COLOR]
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi