Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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:使用fetchall()显示表数据_Php_Mysql_Arrays_Fetchall - Fatal编程技术网

PHP:使用fetchall()显示表数据

PHP:使用fetchall()显示表数据,php,mysql,arrays,fetchall,Php,Mysql,Arrays,Fetchall,快速PHP/MySQL问题: 我试图将MySQL数据库表中的数据显示为HTML表,出于某种原因,我的代码将每条数据的输出加倍 这是我的代码: $rowarray = $statement->fetchall(); print "<tr>\n"; foreach ($rowarray as $row) { foreach ($row as $col) { print "\t<td>$col</td>\n"; }

快速PHP/MySQL问题:

我试图将MySQL数据库表中的数据显示为HTML表,出于某种原因,我的代码将每条数据的输出加倍

这是我的代码:

$rowarray = $statement->fetchall();
print "<tr>\n";  
foreach ($rowarray as $row) {
    foreach ($row as $col) {
        print "\t<td>$col</td>\n";
    }
    print "</tr>\n";
}  
$rowarray=$statement->fetchall();
打印“\n”;
foreach($rowarray作为$row){
foreach(行作为$col){
打印“\t$col\n”;
}
打印“\n”;
}  
我的结果与此类似:

用户ID |用户名|名|姓

11用户名用户名用户名首名首名姓氏姓氏


等等,你明白了。为什么会这样?顺便说一下,如果我通过参考第[]行下标0-3手动添加列信息,则所有内容都会正确显示;只有当我使用嵌套的foreach语句时,数据才会被复制。

您才能从中获得数字和名称索引值。要仅获取数字索引,请执行以下操作:

$rowarray = $statement->fetchall(PDO::FETCH_NUM);

就在那里!非常感谢你。