Php 学生';s马克报告
请帮我写这段代码 我想这样展示桌子 根据学生ID从三个数据库表生成 所以我想显示这个表,没有任何考试或科目的固定值。。我是这样做的,效果很好,但我希望知道这是不是最好的方法Php 学生';s马克报告,php,mysql,Php,Mysql,请帮我写这段代码 我想这样展示桌子 根据学生ID从三个数据库表生成 所以我想显示这个表,没有任何考试或科目的固定值。。我是这样做的,效果很好,但我希望知道这是不是最好的方法 <? $con = mysql_connect("localhost","root","123"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con);
<?
$con = mysql_connect("localhost","root","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
////////////////////////
///////////////// Select the exams and put it in array
$ex = mysql_query("SELECT * FROM exams");
$dc=1;
while ($rowex= mysql_fetch_array($ex)){
$exn[$dc]=$rowex['Exam_Title'];
$exid[$dc]=$rowex['Exam_ID'];
$dc++;
}
/////////////////////////// Select the subjects and put it in array
$sj = mysql_query("SELECT * FROM subjects");
$dsj=1;
while ($rowsj= mysql_fetch_array($sj)){
$sjn[$dsj]=$rowsj['Subj_Title'];
$sjid[$dsj]=$rowsj['Subj_ID'];
$dsj++;
}
////////////////Select the student marks and put it in array with subject id and exam id
$result = mysql_query("SELECT * FROM stu_marks");
while ($row= mysql_fetch_array($result)){
$arr[$row['Subj_ID']][$row['Exam_ID']]=$row['Grade'];
}
/////////////////////// count the exams and the subjects to draw the table
$exc=count($exn);
$sjc=count($sjn);
?>
<table width="400" border="1">
<tr>
<?
///////// display subjects in table rows
for ($d=0;$d<=$sjc;$d++){
if ($d==0){
echo '<td>-</td>';
}else{
echo ' <tr><td>'.$sjn[$d].'</td>';
}
///////// display exams in table head tds
for ($p=1;$p<=$exc;$p++){
if ($d==0){
echo '<td> '.$exn[$p].'</td>';
}else{
?>
<td>
<?=$arr[$sjid[$d]][$exid[$p]]?>
</td>
<?}
}
}?>
</table>
我只是问这是不是一个好方法
对不起,我说的是英语如果代码按原样工作,您只想知道是否有更好的方法,然后是比这里更合适的方法。您实际需要什么帮助?我看不出有什么特别的问题。你有什么问题?它是与PHP相关的还是需要html表方面的帮助?我只是问这是否是一个好方法。。好的,我会在另一个地方问的谢谢谢谢。。我会试试你的建议