简体   繁体   English

PHP中的多维数组

[英]Multi dimensional array in PHP

I have values in my attendance table as follows我的出勤表中有如下值

在此处输入图片说明

sl_no is Foreign key reference register_table( sl_no ) sl_no 是外键引用 register_table( sl_no )
register_table Contains details about students like student_name etc... register_table 包含有关学生的详细信息,例如 student_name 等...

My question is ,我的问题是
How can i get Attendance report in Table Format (Like Excel) Using Multi dimentional Array如何使用多维数组以表格格式(如 Excel)获取考勤报告

UPDATE更新

I'm Querying the database as below, but am getting the results of same students in multiple rows, wherever they present it will create NEW ROW, I'm expecting to display in table format with different dates header for the same student name by using 2 dimensional array.我正在按如下方式查询数据库,但是我在多行中获取相同学生的结果,无论他们出现在哪里,它都会创建新行,我希望通过使用以表格格式显示相同学生姓名的不同日期标题二维数组。

$sql="SELECT att.present,att.AttDate,r.student_name,r.university,r.batch FROM register_table as r inner join attendance as att on r.sl_no=att.sl_no WHERE university LIKE '$sdluniversity'";
     $result=mysqli_query($link, $sql);
     while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
          echo "<tr>";
          echo "<td>".$row['student_name']."</td>";
          echo "<td>".$row['present']."</td>";
          echo "<td>".$row['AttDate']."</td>";
          echo "<td>".$row['university']."</td>";
          echo "<td>".$row['batch']."</td>";
          echo "</tr>";
     }

Please Suggest me what are all the changes I need to make in the above code or my code is totally wrong to achieve my requirement.请建议我在上面的代码中需要进行哪些更改,或者我的代码完全错误以实现我的要求。

I would like the output to look like this :我希望输出看起来像这样:

         Date1    Date1   Date3    University   Batch Average
Student1 present  present present Myuniversity  2012  100%
Student2 present  Absent  Absent  Myuniversity  2013  33%
Student3 present  present present Myuniversity  2012  100%

Like Excel Attendance Report, As I'm New webie Any help may greatly appreciated.像 Excel 出勤报告一样,因为我是新人 webie 任何帮助都将不胜感激。

Use inner join on tables as在表上使用内部联接作为

$sql='select att.present,r.university,r.name,r.rollNo from register as r inner join  attendance as att on r.sl_no=att.sl_no';
$sql = mysqli_query($con, $query);
$attendence = array();

while ($data = mysqli_fetch_assoc($sql)){

 if (!array_key_exists($data['userId'], $attendence))
    $attendence[$data['userId']]['student'] = $data['userId'];

$attendence[$data['userId']][$data['date']] = $data['present'];

}

echo "<pre>";
var_dump($attendence);

iterate each index of $attendence array to form a table having index as userId,dates you can also calculate average of their attendance迭代$attendence数组的每个索引以形成一个表,索引为 userId,dates 你也可以计算他们的出勤率

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM