如何为单个ID显示单独的单独视图?

时间:2014-12-18 12:13:26

标签: php mysql

视图应该如下:

Term 1
Result of term 1
Other activities of term 1

Term 2
Result of term 2
Other activities of term 2

Term3
Result of term 3
Other activities of term 3

但是我的代码显示了以下视图:

Term 1
Term 2
Term 3

Result of term 2
Result of term 2
Result of term 2

Other activities of term 1
Other activities of term 2
Other activities of term 3

我想显示数据' term'明智....

这是我的代码.....

<?php   
include_once('config.php'); 

$cls = $_SESSION['cls'];
$student_id = $_SESSION['student_id'];

$sql = "SELECT * from class_6 WHERE  class_name='$cls' AND student_id='$student_id'";

$retval = mysql_query($sql,$connection);
if(! $retval )
{
    die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
    echo "<b>Term</b> : {$row['term']}<br>";
    echo "<tr><td>{$row['bangla1']}</td>".
             "<td>{$row['bangla1_om']}</td>".
         "<td>{$row['bangla1_hm']}</td>".
         "<td>{$row['bangla1_tm']}</td>".
         "<td>{$row['bangla1_grade']}</td></tr>".

         "<tr><td>{$row['bangla2']}</td> ".
         "<td>{$row['bangla2_om']} </td>".
         "<td>{$row['bangla2_hm']} </td>".
         "<td>{$row['bangla2_tm']} </td>".
         "<td>{$row['bangla2_grade']} </td></tr>";
}
?>

1 个答案:

答案 0 :(得分:0)

您需要在周期中包含Term-Result-Other组。很难跟踪视图中的内容,因为没有可比较的DB结构。

此外,我强烈建议您开始使用PDO或任何可以保护数据库请求的ORM。

在您的特定示例中:

while(<your-results>) {
    echo "Term: " . $row['term'];
    echo "Result:" . <whatever-row-fields>;
    echo "Other activities:" . <again-whatever-rows>
}