ronquiq
ronquiq

Reputation: 2717

Showing rows in table headers

I have a table like

id       course       activities   

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

I need to show in php file as table header

Quiz1   Quiz2   Quiz3    Quiz3  Quiz4

And this is my code

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

Upvotes: 0

Views: 81

Answers (1)

zessx
zessx

Reputation: 68790

You just have to reorganize your code :

<?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>';
?>

Upvotes: 1

Related Questions