Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从MySQL动态生成HTML表_Php_Html_Mysql - Fatal编程技术网

Php 从MySQL动态生成HTML表

Php 从MySQL动态生成HTML表,php,html,mysql,Php,Html,Mysql,我有三门课,考试,考试 表格-科目 主体 主题名 受试者 表-检查 埃克萨米德 考试 表格检查 fname 名字 学生 得分 主体 关于subject.subjectExamid=exam.examid 在考试中。主语 现在,我想生成一个HTML表格,显示学生在每一篇论文中针对主题所获得的分数 结构表输出 每个科目分数的学生详细信息 编辑代码示例 <?php $examinid = 3; $subjects = mysqli_query( $con,"

我有三门课,考试,考试

表格-科目

  • 主体
  • 主题名
  • 受试者
  • 表-检查

  • 埃克萨米德
  • 考试
  • 表格检查

  • fname
  • 名字
  • 学生
  • 得分
  • 主体

    关于subject.subjectExamid=exam.examid

    在考试中。主语

  • 现在,我想生成一个HTML表格,显示学生在每一篇论文中针对主题所获得的分数

    结构表输出 每个科目分数的学生详细信息

    编辑代码示例

    <?php
      $examinid = 3;
      $subjects = mysqli_query(
          $con," 
              SELECT * FROM subjects
              WHERE examid = '$examinid'
              ORDER BY shortname ASC
    
      ");
      $content = mysqli_query(
          $con," 
              SELECT DISTINCT exam.idcandidate, exam.sex, exam.fname, exam.lname
              FROM examinations 
              AS exam
              INNER JOIN examinfo
              AS info
              ON exam.id_subject = info.idsubject
              WHERE info.idexam = '$examinid'         
      ");
    ?>
    <div id="table_1">
      <table cellpadding="0" cellspacing="0" border="0">
          <tr>
              <td class="table1tr">#</td> 
                <td class="table1tr">Candidate</td>   
                <td class="table1tr">ID</td>  
                <td class="table1tr">Sex</td> 
              <?php
                  // output subjects 
                  while($subRow = mysqli_fetch_array($subjects)){
                      $arbv = strtoupper($subRow['shortname']);
                      $subjectname = ucwords(strtolower($subRow['subjectname']." - ".$subRow['subjectid'].""));
              ?>
              <td class="table1tr" title="<?php echo $subjectname; ?>">
                  <?php echo $arbv; ?>
                </td>
              <?php   
                  }
              ?>                  
                <td class="table1tr">Exam</td>
            </tr>
          <?php
              while($stdnt = mysqli_fetch_array($content)){
                  $fullname = ucwords(strtolower("$stdnt[lname] $stdnt[fname]"));
                  $studentid = str_replace(array('/', 'M', 'W', 'S', 'F', '-'), "",$stdnt['idcandidate']);
                  if($sex = $stdnt['sex'] == Male){
                      $sex = M;
                  }else{ $sex = F; }
                  $id_subject = $stdnt['id_subject'];
                  $x++;
                  $zebra_1 = ($x%2)? 'TableZebra_1': 'TableZebra_2';
          ?>        
          <tr>
              <td class="<?Php echo $zebra_1; ?>"><?php echo $count++; ?></td>    
                <td class="<?Php echo $zebra_1; ?>"><?Php echo $fullname; ?></td> 
                <td class="<?Php echo $zebra_1; ?>"><?php echo $studentid; ?></td>    
                <td class="<?Php echo $zebra_1; ?>"><?php echo $sex; ?></td>
              <td class="<?Php echo $zebra_1; ?>">
                <!-- Problem is here how to output the subject grades $grade -->
                <!-- 
                    My first unsuccessful approach  
    
                    SELECT score
                    FROM examinations AS test
                    INNER JOIN examinfo AS testinfo ON testinfo.idsubject = test.id_subject
                    WHERE testinfo.idexam
                    IN (
    
                    SELECT idexam
                    FROM examinfo
                    WHERE idexam = $examinid
                    )
                    AND test.id_subject = $id_subject AND test.idcandidate = '$studentid'
    
                    Then output results - But this falls it shows one student subjects in one cell
                -->
                </td> 
                <td class="<?Php echo $zebra_1; ?>">Exam</td>
            </tr>        
              <?php   
                  } // loop content
              ?>      
    
        </table>  
     </div>
    
    
    
    如果您的解决方案不是concat();你可以先

    遵循简单的步骤

    1 loop $contents // to get info such as studentid
    2 inside the loop of $contents loop $subjects // to get all subjects including subjectids
    3 inside $subject loop, loop examinations table where studentid = '$studentid' AND subjectid = '$subjectid'
    if step three return null echo empty cell otherwise echo cell with score
    

    我没有时间测试这个,但是你可以按照步骤操作,否则它会工作的,试试谷歌搜索

    我们不会为你神奇地编写代码。。。如果您想尝试并发布它,那么我很乐意帮助您解决代码中的错误。。但是堆栈溢出不是为了给你的工作编码。。你应该从一些研究开始约翰·鲁德尔检查编辑