douyong1974 2015-04-15 11:16
浏览 41
已采纳

将数据返回到数据库MYSQL的PHP​​页面

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: enter image description here

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 :
List of entity

Detail of table "Composto"

Detail of "turni"

Detail of "Militi"

  • 写回答

1条回答 默认 最新

  • dtvfshi5248 2015-04-15 11:50
    关注

    I am not going to justify either your database design Or coding is poor in best case your whole purpose will/should need one query. From your question as far as I understand you need a query that will pull data of one week(or.. ). modify your query like this

    $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 between \"2015-04-26\" AND \"2015-04-30\" ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现