我从数据库中获取表头和表数据。 表数据的结果取决于标题的结果, 我发现很难在表头之间调用表行,下面的表数据是我的代码
<?php
mysql_connect("localhost", "root", ""); mysql_select_db("javanet");
$sql=mysql_query("select * from course_pos_map inner join courses on
course_pos_map.course_id=courses.course_id where dept_id=1");
echo "<table border=1><tr>";
while($row=mysql_fetch_array($sql))
{
echo "<th>$row[alias]</th>"; # this is the table header , tr is suppose to come
here so as to break table row below
$csql=mysql_query("select * from student_course_regs where
co_pos_map_id='$row[co_map_id]'");
while($row2=mysql_fetch_array($csql))
{
echo "<td>$row2[total_score]<td>"; # this is the table row, it is suppose
to be under the header
}
}
echo "</table>";
?>
答案 0 :(得分:0)
我能够理解你的问题的答案。你没有使用tr标签 试试这个代码,如果我没错,请不要忘记投票
<?php
mysql_connect("localhost", "root", ""); mysql_select_db("javanet");
$sql=mysql_query("select * from course_pos_map inner join courses on
course_pos_map.course_id=courses.course_id where dept_id=1");
echo "<table border=1><tr>";
while($row=mysql_fetch_array($sql))
{
echo "<tr><th>$row[alias]</th></tr>"; # this is the table header , tr is suppose to come here so as to break table row below
$csql=mysql_query("select * from student_course_regs where co_pos_map_id='$row[co_map_id]'");
while($row2=mysql_fetch_array($csql))
{
echo "<tr><td>$row2[total_score]<td></tr>"; # this is the table row, it is suppose
to be under the header
}
}
echo "</table>";
?>