Php mysqli_fetch_field()多次输出字段名

Php mysqli_fetch_field()多次输出字段名,php,mysql,Php,Mysql,我正在尝试显示数据库中的列名,我可以使用mysqli\u fetch\u field()函数来实现这一点,但是我的问题是,它输出了几次列名,而我只希望它输出每个列名一次。我将我的$field\u info变量设置为该函数,该函数接受设置为我的查询的参数$result,所有这些都被放入我的while循环中。我觉得这可能是我的while循环造成的?但我不太确定 $query = "SELECT * FROM bodyshops_master_network"; if ($result = $mys

我正在尝试显示数据库中的列名,我可以使用
mysqli\u fetch\u field()
函数来实现这一点,但是我的问题是,它输出了几次列名,而我只希望它输出每个列名一次。我将我的
$field\u info
变量设置为该函数,该函数接受设置为我的查询的参数
$result
,所有这些都被放入我的while循环中。我觉得这可能是我的while循环造成的?但我不太确定

$query = "SELECT * FROM bodyshops_master_network";

if ($result = $mysqli->query($query))
{

// print the column names as the headers of a table 
while ($field_info = mysqli_fetch_field($result))
{
    printf("postcodes_covered %s\n", $field_info->postcodes_covered);
    printf("dealer_code %s\n", $field_info->dealer_code);
    printf("dealer_name %s\n", $field_info->dealer_name);
    printf("bodyshop_id %s\n", $field_info->bodyshop_id);
    printf("bodyshop_name %s\n", $field_info->bodyshop_name);
    printf("address1 %s\n", $field_info->address1);
    printf("address2 %s\n", $field_info->address2);
    printf("address3 %s\n", $field_info->address3);
    printf("address4 %s\n", $field_info->address4);
    printf("address5 %s\n", $field_info->address5);
    printf("postcode %s\n", $field_info->postcode);
    printf("BO_tel %s\n", $field_info->BO_tel);
    printf("BO_email %s\n", $field_info->BO_email);
    printf("BC_name %s\n", $field_info->BC_name);
    printf("equity_contract %s\n", $field_info->equity_contract);

}
试着这样做:

// making a query
$query = "SELECT * FROM bodyshops_master_network";

// firing a query and getting the resource in $result variable
$result = $mysqli->query($query);

$i = 0;

// loop all fields
while ($i < mysqli_field_count($result)) {

    // fetching field information. Index of the field is given by $i
    $meta = mysqli_fetch_field($result, $i);
    // display information for each field here
    .
    .
    //
    $i++;
}
//进行查询
$query=“从车身车间\主机\网络中选择*”;
//触发查询并获取$result变量中的资源
$result=$mysqli->query($query);
$i=0;
//循环所有字段
而($i

参考官方文件的重复是否有一种模式,就像每列重复2次一样?它随机打印了15次。因此,每行包含邮政编码、经销商代码、经销商名称……等,打印15次哦,基本上是按元素数量打印列名集。请您向我解释您的代码,因为我对php和mysql@user3009232:当然可以。我将编辑我的答案并添加注释,以便您能够理解。