有一個數組
$row=array("username"=>"admin" "mail"=>"admin@admin.com" "id"=>"1")
我想輸出出來
echo "
";echo "
";echo "
".$row['id']." | ";echo "
".$row['username']." | ";echo "
".$row['id']." | ";echo "
";echo "
";
為什麼表格亂了?每個表格的列寬都會變
回複內容:
有一個數組
$row=array("username"=>"admin" "mail"=>"admin@admin.com" "id"=>"1")
我想輸出出來
echo "
";echo "
";echo "
".$row['id']." | ";echo "
".$row['username']." | ";echo "
".$row['id']." | ";echo "
";echo "
";
為什麼表格亂了?每個表格的列寬都會變
你該不會是每行都建立了一個新的table吧
那就把表的樣式固定唄
foreach迴圈應該在table裡,不是在外面
看一下你貼的圖,行分割線比較粗,列分割線比較細,多半是每行都是一個table
應該遍曆tr td
首先樓主你的數組的寫的就不對,應該是$row=array("username"=>"admin","mail"=>"admin@admin.com","id"=>"1");
如果你的數組是一維數組的話,是這樣的
echo "
";echo "
";echo "
".$row['id']." | ";echo "
".$row['username']." | ";echo "
".$row['id']." | ";echo "
";echo "
";
如果數組是二維數組的話,你應該是foreach迴圈放錯了
例如:
$row=array( array("username"=>"admin","mail"=>"admin@admin.com","id"=>"1"), array("username"=>"uer1","mail"=>"user1@user.com","id"=>"2"), array("username"=>"uer2","mail"=>"user2@user.com","id"=>"3") ); echo "
";foreach ($row as $key => $value) { echo "
"; echo "
".$value['id']" | "; echo "
".$value['username']." | "; echo "
".$value['id']." | "; echo "
";}echo "
";樣式: