Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 循环遍历表中的每个单元格并获取其各自的标题_Php_Mysql_Sql_Mysqli - Fatal编程技术网

Php 循环遍历表中的每个单元格并获取其各自的标题

Php 循环遍历表中的每个单元格并获取其各自的标题,php,mysql,sql,mysqli,Php,Mysql,Sql,Mysqli,下面是我的表格示例。我知道它不好。一些网站提供了这样的数据。我需要转换成更好的格式 所以我想循环遍历所有的单元格,得到它们各自的标题 例如,输出应为 01001 - Dairy and Egg Products 01002 - Dairy and Egg Products . . . . 02001 - Spices and Herbs 02002 - Spices and Herbs 我的代码到目前为止在php中,我很抱歉我在stackoverflow和google中搜索到了答案,我不知道

下面是我的表格示例。我知道它不好。一些网站提供了这样的数据。我需要转换成更好的格式

所以我想循环遍历所有的单元格,得到它们各自的标题

例如,输出应为

01001 - Dairy and Egg Products
01002 - Dairy and Egg Products
.
.
.
.
02001 - Spices and Herbs
02002 - Spices and Herbs
我的代码到目前为止在php中,我很抱歉我在stackoverflow和google中搜索到了答案,我不知道怎么做。非常感谢您的帮助

$qrelated= inputs("SELECT * FROM `table`");

while($row = $qrelated->fetch_assoc())
{

}

您可以使用
foreach
循环打印每个列标题及其每行的值,如下所示:

foreach($row as $key => $value) {
    echo $value." - ".$key;
}

foreach($key=>row as$value){echo$value.-“$key;}
?谢谢!我真是个傻瓜。现在我明白了。你能回答这个问题让我接受吗?还是我把这个愚蠢的问题删掉呢。如果你愿意接受,我已经通过评论发布了答案。您可以随时编辑您的问题,使其更加通用,并将此问题保留在此处,以用作链接到其他类似问题的规范答案