PHP / mySQL查询多个sql表到1个html表中

时间:2014-12-11 17:23:51

标签: php mysql

我有一个调度应用程序,我需要构建一个html表格报告。我需要从usersattandanceweekshift表中获取数据。我还有一个数组,告诉我他们有多少出勤代码和描述。

为了演示:http://sqlfiddle.com/#!2/8f8a6f

table users:                     table attendance:
userid | name                    userid | code
test   | Test user               test   | 2

table week:                      table shift
week | status                    userid | week | shift | status
1207 | 1                         test   | 1207 | tue   | 1
1214 | 1                         test   | 1207 | wed   | 1
1221 | 0

我需要得到:

  • userid:users.userid
  • 名称:users.name
  • 在考勤阵列的循环中
    • 出勤代码总和:attendance.code where attendance.userid=users.userid AND code=1总和,出勤总和等。
  • week where status != 0的循环中
    • 轮班工作次数:计算shift where shift.userid = users.userid AND shift.week = week.week AND status != 0

所以我得到这样的东西:

User ID | Name      | Attendance   | Att2      | Week of | Week of
        |           | code 1 (late)|(unexcused)| 12/07   | 12/14
test    | Test user | 0            | 1         | 2       | 3

我目前有很多循环。 我将users表放入一个数组,然后为每个用户循环该数组,然后循环我的出勤数组查询出勤表。然后再次循环用户数组查询每周的轮班表。我想看看是否有办法在SQL中做到这一点。

0 个答案:

没有答案
相关问题