如何使用循环垂直打印数据

时间:2017-08-20 09:02:23

标签: php html mysql

我有以下问题。 我打印了一个表名考试的数据,该考试有student_id和marks_obtained为每个student_id和。我的输出如下

enter image description here

但我想要不同格式的表格

-----------------------
subject | marks | total
-----------------------
向下看 因为这看到输出

enter image description here

但我在代码中感到困惑请帮助我 我的代码如下:

$roll=$_POST['roll'];
$exam=$_POST['exam'];
$int1 = intval(preg_replace('/[^0-9]+/', '', $exam), 10);

$student_info="select student_id,name,father_name,mother_name,roll,class_id,birthday,parent_id from student where roll='$roll'";
$result_student=mysqli_query($link, $student_info) OR trigger_error('login info error');
$data_student= mysqli_fetch_array($result_student,MYSQL_BOTH);


$parent_info="select name from parent where parent_id='$studentparent'";
$result_parent=mysqli_query($link, $parent_info) OR trigger_error('login info error');
$data_parent= mysqli_fetch_array($result_parent,MYSQL_BOTH);

$parentname= $data_parent['name'];

$subject_info="select subject_id,name from subject where class_id='$studentclass'";
$result_subject=mysqli_query($link, $subject_info) OR trigger_error('login info error');
$data_subject= mysqli_fetch_array($result_subject,MYSQL_BOTH);

1 个答案:

答案 0 :(得分:0)

<table>
 <tr>
  <td> Subject </td>
  <td> Marks </td>
  <td> Total </td>
 </tr>
 <tr>
 <?php
 for($i=0;i<count($data);i++){
 ?>
  <td><?php echo $data['subject_name'];?></td>
  <td><?php echo $data['marks'];?></td>
  <td><?php echo $data['total'];?></td>
 <?php
 } 
 </tr>
</table>