php - 动态回显所有列名称和所有行

标签 php mysql sql rows

哟兄弟,我正在尝试回显表中的所有数据,包括列名和字段。我能够成功获取列名,我还想获取所有行和字段,我不确定我是否采取了正确的方法来解决我的问题,请帮助。

//this is to echo coloumn names
$table = '<table border="1" cellspacing="10" cellpadding="10" style="width:60%">';
$table2 = "</table>";
$sql2 = "SHOW COLUMNS FROM $tablename";
$query2 = mysqli_query($conn,$sql2);
$tablename = $_POST['db'];
echo $table;
while($row = mysqli_fetch_array($query2)){
echo $row[0] . "&nbsp;&nbsp;&nbsp;";
}
echo $table2 . "<br /><br />";
// successful in echoing coloumn names

// now i want to echo rows based on the number of coloumns
$countcol = mysqli_num_rows($query2);
$sql = "SELECT * FROM $tablename";
$query = mysqli_query($conn,$sql);

echo $table;
$i = "";
while($row=mysqli_fetch_array($query)){
for($i=0;$1<$countcol;$i++){
echo $row[0];
}
}
echo $table2 . "<br /><br />";
// this doenst get the all the rows based on the no of coloumns

最佳答案

在最后一个循环中,echo $row[0] 是正确的还是 $row[$i]

关于php - 动态回显所有列名称和所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28265878/

相关文章:

php - 嘿,所以我得到了一个 - fatal error : "Uncaught Error: Call to undefined function utf8_encode() in"

php - 如何将参数传递给 Laravel 5 中的隐式 Controller ?

javascript - 使用 JSON 在 php 中附加一个文本文件,不起作用并且没有显示错误消息

mysql - 重复的行

mysql - 优化正则表达式查询

sql - Postgres 使用 UnknownType 值将两个字段合二为一

php - 在 PHP 中执行外部 BLAST 程序

SQL服务器 : How to sort table names ordered by their foreign key dependency

sql - 如何找出哪些 SQL Server 表链接到 MS Access?

mysql查询路径/半径