function table($sql,$border)
{
$con = mysqli_connect("localhost","root","","dbit36");
$resource = mysqli_query($con,$sql);
echo"<table border=0>";
for($i = 0; $i < mysqli_num_fields($resource); $i++)
{
echo "<td style='border:".$border."1px dotted;'><b><font color='990099'size='10'>".mysql_field_name( $resource, $i )."</b></font></td>";
}
echo "</tr>";
while($row = mysqli_fetch_array($resource))
{
echo "<tr>";
for($i = 0; $i < mysqli_num_fields($resource); $i++)
{
echo "<td style='border:".$border."px ridge;'>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
我知道在 php 5.5+ 版本中不推荐使用 mysql
函数,这就是为什么我的问题是有没有 mysqli
函数可以获取指定字段的名称结果?
最佳答案
通过使用mysqli_fetch_assoc
而不是mysqli_fetch_array
然后,您可以通过键入 $row['field_name']
关于php - 如何使用 mysqli 函数获取结果中指定字段的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32196105/