(php)使用来自DB的数据循环表头

时间:2016-04-19 12:31:57

标签: php mysql

我试图将数据从数据库循环到表头,这些是我的代码到目前为止。

<table name="Score_Filtering" style="width:100%">
<tr>
<th>Name</th>
<th>Lastname</th>   

<?php 

for($i = 0; $i < $count; $i++){
?>
<th><?php echo $rowss['Skill_Name'] ?> Score</th>
<?php 
}
?>

<th>Overall Score</th>
<th>Status</th>
<th>View Information</th>

</tr>

</table>

假设&#34; $ rowss&#34;已声明

 $result2 = mysql_query("SELECT * FROM mytable");
 $rowss = mysql_fetch_array($result2, MYSQL_ASSOC);

除了......之外我觉得这张桌子没问题。

 <th><?php echo $rowss['Skill_Name'] ?> Score</th>

此部分仅显示&#34;得分&#34;在标题上,但没有数据库中的数据,我希望它插入&#34;分数&#34;。

有关如何执行此操作或指导我朝正确方向的任何建议。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

首先,不要使用已弃用的mysql_*函数,并在PHP 7中完全删除。

回到你的问题,你从数据库中获取多行,所以,使用while循环。

while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
 // Your code
}