使用PHP以电子表格形式打印MySQL结果?

时间:2014-11-27 17:34:08

标签: php mysql

这里的M代码就像HTML一样打印出来,我想知道是否有一种方法可以格式化为HTML表格,如格式,顶部有列名

print "Skill ||| Pay Rate";
while($row = mysqli_fetch_array($result, MYSQLI_BOTH))
  {

    print "\n";
    print "$row[skill_Description], $row[skill_PayRate] ";
  }

我正在研究jquery,但我真的很擅长这个

1 个答案:

答案 0 :(得分:0)

你的意思是这样吗?

print "<table class='table'>\n\t<tr>\n";    
for ($i = 0; $i < mysqli_num_fields ($res); $i++)
{       
    print "\t\t<th>".mysqli_fetch_field_direct ($res, $i)->name."</th>\n";      
}       
print "\t</tr>\n";

while (($row = mysqli_fetch_assoc ($res)))
{
    print "\t<tr>\n";
    foreach ($row as $val)
    {
        print "\t\t<td>".$val."</td>\n";
    }
    print "\t</tr>\n";
}   
print "</table>";