什麼是最佳方式插入1000行和10列的數組到每個mysql表格下面是我如何顯示它,所以它會是一個類似的結構,但我需要一些方向將php嵌套數組插入到mysql表中
foreach ($stack as $val) {
print "<tr>\n";
foreach ($val as $no) {
print " <td>$no</td>\n";}
print "</tr>\n";
}
什麼是最佳方式插入1000行和10列的數組到每個mysql表格下面是我如何顯示它,所以它會是一個類似的結構,但我需要一些方向將php嵌套數組插入到mysql表中
foreach ($stack as $val) {
print "<tr>\n";
foreach ($val as $no) {
print " <td>$no</td>\n";}
print "</tr>\n";
}
插入成千上萬的數據到數據庫更好的辦法是使用破滅功能implode
我猜你長了這樣的事情
$stack = array("man1" => array("name"=>"ik", "class"=>"highskl", "age"=> "12"),"man1" => array("name"=>"ijk", "class"=>"higkl", "age"=> "13"));
,並要將其插入表,嘗試使用表字段作爲內部陣列的索引,然後調整代碼,使其看起來像這樣
foreach ($stack as $entry => $value) {
$query = "INSERT INTO table set ";
foreach ($value as $key => $val) {
$query .= $key ."= ".$val.",";}
//use a string function to remove the last comma
$result = mysql_query($query) or die("Error in Query ".$entry." ",mysql_error());
//this helps to track error..
}
對不起,這來得晚了......電源故障! –