0
生成HTML表我有三個MySQL表科目,考試,examinfo動態地從MySQL
表 - 科目
- subjectid
- 主旨名稱
- subjectExamid
表 - EXAMINFO
- examid
- 考試
TABLE EXAMINATIONS
- FNAME
- L-NAME
- studentid
- 得分
subjectid
ON subject.subjectExamid = exam.examid
ON examination.subjectid = subject.subjectid
現在我想生成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>
我們不會奇蹟般地代碼爲你...如果你想做一個嘗試併發布它,那麼我會很樂意幫助你在代碼中的錯誤..但堆棧溢出不是爲你的工作編碼..你應該從一些研究開始[**簡單的Google搜索**](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=php%20generate%20html%20table%20from%20mysql) – 2014-10-12 02:39:12
約翰ruddell檢查編輯 – firstmadcoding 2014-10-12 09:22:23