In another question i have asked how to develop a custom database for a particular request, the database is now complete with data-
So, now I'm trying to develop a simple php page, the problem that i dont know how i can display some data correctly.
Now i have a structure that represent a list of working shifts.
Each day is divided in four parts :
Night (24.00 - 08:00)
Morning (08.00 - 14.00)
Afternoon (14.00 - 20.00)
Evening (20.00 - 24.00)
In each turn (Night or Morning or arthernoon or evening) one or max three worker can may decide to partecipate.
For example:
Day : 13/04/15
Night : Person a , Person b, Person c
Morning : Person d, Person e, Person f
Now i need a page that represents the data in the database, in particular a weekly representation of the shifts
I would show a page like this:
Actually i wrote this code, that returns (obviously) shifts in a certain date:
<?php
mysql_set_charset('utf8');
date_default_timezone_set('Europe/Rome');
$today_is = date("Y-m-d");
$listaN = array();
$queryN = "SELECT cognome, ruolo, orario, data FROM Composto, Militi, Turni WHERE (Composto.id_milite = Militi.id_milite AND Composto.id_turno = Turni.id_turno AND orario =\"Notte\" AND data = \"2015-04-26\")";
$result = mysql_query($queryN);
$num = mysql_num_rows($result);
if ($num != 0) {
while ($row = mysql_fetch_assoc($result)) {
array_push($listaN, $row);
}
}
$autista = "";
$milite = "";
$tirocinante = "";
foreach($listaN as $i){
$giorno = $i['data'];
if ($i['ruolo'] == "Autista"){
$autista= $i['cognome'];
}else if($i['ruolo'] == "Milite"){
$milite= $i['cognome'];
}else{
$tirocinante= $i['cognome'];
}
}
print("
<table border=\"1\">
<tr>
<td rowspan=\"6\">
".$giorno."
</td>
<td>
Orario
</td>
<td>
Autista
</td>
<td>
Milite
</td>
<td>
Tirocinante
</td>
</tr>
<tr>
<td>
00.00 - 08.00
</td>
<td>
".$autista."
</td>
<td>
".$milite."
</td>
<td>
".$tirocinante."
</td>
</tr>
");
$listaM = array();
$queryM = "SELECT cognome, ruolo, orario,data FROM Composto, Militi, Turni WHERE (Composto.id_milite = Militi.id_milite AND Composto.id_turno = Turni.id_turno AND orario =\"Mattino\"AND data = \"2015-04-26\")";
$result = mysql_query($queryM);
$num = mysql_num_rows($result);
if ($num != 0) {
while ($row = mysql_fetch_assoc($result)) {
array_push($listaM, $row);
}
}
$autista = "";
$milite = "";
$tirocinante = "";
foreach($listaM as $i){
if ($i['ruolo'] == "Autista"){
$autista= $i['cognome'];
}else if($i['ruolo'] == "Milite"){
$milite= $i['cognome'];
}else{
$tirocinante= $i['cognome'];
}
}
print("
<tr>
<tr>
<td>
08.00 - 14.00
</td>
<td>
".$autista."
</td>
<td>
".$milite."
</td>
<td>
".$tirocinante."
</td>
</tr>
");
$listaP = array();
$queryP = "SELECT cognome, ruolo, orario,data FROM Composto, Militi, Turni WHERE (Composto.id_milite = Militi.id_milite AND Composto.id_turno = Turni.id_turno AND orario =\"Pomeriggio\"AND data = \"2015-04-26\")";
$result = mysql_query($queryP);
$num = mysql_num_rows($result);
if ($num != 0) {
while ($row = mysql_fetch_assoc($result)) {
array_push($listaP, $row);
}
}
$autista = "";
$milite = "";
$tirocinante = "";
foreach($listaP as $i){
if ($i['ruolo'] == "Autista"){
$autista= $i['cognome'];
}else if($i['ruolo'] == "Milite"){
$milite= $i['cognome'];
}else{
$tirocinante= $i['cognome'];
}
}
print("
<tr>
<td>
14.00 - 20.00
</td>
<td>
".$autista."
</td>
<td>
".$milite."
</td>
<td>
".$tirocinante."
</td>
</tr>
");
$listaS = array();
$queryS = "SELECT cognome, ruolo, orario,data FROM Composto, Militi, Turni WHERE (Composto.id_milite = Militi.id_milite AND Composto.id_turno = Turni.id_turno AND orario =\"Sera\"AND data = \"2015-04-26\")";
$result = mysql_query($queryS);
$num = mysql_num_rows($result);
if ($num != 0) {
while ($row = mysql_fetch_assoc($result)) {
array_push($listaS, $row);
}
}
foreach($listaS as $i){
if ($i['ruolo'] == "Autista"){
$autista= $i['cognome'];
}else if($i['ruolo'] == "Milite"){
$milite= $i['cognome'];
}else{
$tirocinante= $i['cognome'];
}
}
print("
<tr>
<td>
20.00 - 24.00
</td>
<td>
".$autista."
</td>
<td>
".$milite."
</td>
<td>
".$tirocinante."
</td>
</tr>
");
?>
Now the question is: how i can modify this code and return the data correctly ? I need a single page that contains a view of all the work shifts of the current week, from Monday through Sunday.
I wish I had this chance to see also the following weeks by pressing on a button
*********** EDIT 1 *********** Actually this page return ONLY the data in a certain data, in this case 2015-04-26, what i want is a weekly representation, i dont know how i can get data from db and represent it...
The database is like this :