請幫我寫這段代碼 我想這樣 http://imageshack.us/photo/my-images/443/reportw.jpg/學生的痕跡報告
從三個數據庫表生成的顯示錶依賴於學生證
http://img51.imageshack.us/img51/1272/tablesh.jpg
所以我要展示這個表沒有任何固定值的考試或科目..我這樣做,這是行之有效的,但我希望知道這是否是最好的方式
<?
$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>
我問只是如果這是這樣做
對不起我的英語
你實際上需要什麼幫助?我在這裏沒有看到具體的問題。 – Amber 2012-07-06 16:27:34
你有什麼問題?它是PHP相關還是你需要幫助與HTML表? – Christoffer 2012-07-06 16:32:07
我問只是這是一個好辦法做到這一點..好吧,我會問在另一個地方謝謝你 – HawkEye 2012-07-06 17:21:07