在这个程序中,我从数据库中获取了列名,但在尝试将其保存在数组中时,它会将最后一个列名存储在数组中。如何将 eash 列名存储在数组中???
$sql="SHOW COLUMNS from itasd2015sem1semester";
if(($result=$conn->query($sql))==true){
while($row=$result->fetch_array()){
for($i=0;$i<11;$i++){
$sub[$i]=$row[0]."\n";
}
}
}
for($i=0;$i<sizeof($sub);$i++){
echo $sub[$i];
}
它只打印最后一列的名称??
$sql="SHOW COLUMNS from itasd2015sem1semester";
if(($result=$conn->query($sql))==true){
while($row=$result->fetch_array()){
for($i=0;$i<11;$i++){
$sub[$i]=$row[$i]."\n";
}
}
}
for($i=0;$i<sizeof($sub);$i++){
echo $sub[$i];
}
它显示一条通知..并且它还单独打印最后一列。
Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 6 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 7 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 8 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 9 in C:\xampp\htdocs\new\test1.php on line 21 Notice: Undefined offset: 10 in C:\xampp\htdocs\new\test1.php on line 21
最佳答案
试试这个:
$sql = "SHOW COLUMNS from itasd2015sem1semester";
if (($result = $conn->query($sql)) == true) {
while ($row = $result->fetch_array()) {
$sub[] = $row[0];
}
}
for ($i = 0; $i < sizeof($sub); $i++) {
echo $sub[$i];
}
关于php - 从数据库中获取列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23040079/