在不知道PHP中COL总数的情况下显示mysql表

在不知道PHP中COL总数的情况下显示mysql表,php,html,mysql,Php,Html,Mysql,我需要在代码中显示mysql表列而不指定列名,而且我也不知道表中的列总数 这是我的密码: $result = mysqli_query($con,"SELECT * FROM test_table"); echo "<table border='1'>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; foreach ($row as $item){ echo "<t

我需要在代码中显示mysql表列而不指定列名,而且我也不知道表中的列总数

这是我的密码:

$result = mysqli_query($con,"SELECT * FROM test_table");
echo "<table border='1'>";
while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    foreach ($row as $item){
        echo "<td>" . $item . "</td>";
    }
    echo "</tr>";
}
echo "</table>";
$result=mysqli\u查询($con,“从测试表中选择*);
回声“;
while($row=mysqli\u fetch\u数组($result))
{
回声“;
foreach($行作为$项){
回显“$item.”;
}
回声“;
}
回声“;
但产出如下:

i、 每个列都重复e值。请帮我解决。

更改

while($row = mysqli_fetch_array($result))

这是因为同时获取关联数组和数字数组。尝试使用或

或者,您可以在
mysqli\u fetch\u array
中指定一个参数,如下所示:

mysqli_fetch_array($result, MYSQLI_ASSOC)


我想您正在寻找
mysqli\u fetch\u assoc()
mysqli_fetch_array($result, MYSQLI_ASSOC)
mysqli_fetch_array($result, MYSQLI_NUM)