0

我有一张像

id       course       activities   

1     Microbiology      Quiz1
2     Microbiology      Quiz2
3     Microbiology      Quiz3
4     Microbiology      Quiz4

我需要在 php 文件中显示为表头

Quiz1   Quiz2   Quiz3    Quiz3  Quiz4

这是我的代码

<?php
$sql = mysql_query('SELECT * FROM activity');
while($row = mysql_fetch($sql))
{
    $activities $row['activities'];
}
echo '<table>
       <tr>
        <th>'.$activities.'</th>
       </tr>
     </table>';
?>
4

1 回答 1

1

你只需要重新组织你的代码:

<?php
$sql = mysql_query('SELECT * FROM activity');

echo '<table><tr>';
while($row = mysql_fetch_array($sql))
{
    echo '<th>'.$row['activities'].'</th>';
}
echo '</tr>';

//your data rows here

echo '</table>';
?>
于 2012-07-26T08:14:02.350 回答