在我的mysql數據庫中,我只獲得了id爲26,16,17,18,19,22,23,24的記錄。爲什麼會有這樣的錯誤我的代碼?我不;噸有任何線索,請幫助:(PHP Foreach循環只將部分記錄插入到MySQL表中
<?
$connect = mysql_connect('localhost', 'dbname', 'pass');
if (!$connect) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("dbname") or die(mysql_error());
mysql_query("TRUNCATE TABLE anchors");
$blog_ids = array(
'anchor 1' => '1',
'anchor 2' => '2',
'anchor 3' => '3',
'anchor 2' => '4',
'anchor 2' => '5',
'anchor 4' => '6',
'anchor 5' => '7',
'anchor 6' => '8',
'anchor 7' => '9',
'anchor 8' => '10',
'anchor 9' => '13',
'anchor 10' => '14',
'anchor 11' => '16',
'anchor 12' => '17',
'anchor 13' => '18',
'anchor 14' => '20',
'anchor 15' => '21',
'anchor 16' => '22',
'anchor 17' => '23',
'anchor 18' => '24',
'anchor 19' => '25',
'anchor 20' => '26'
);
foreach($blog_ids as $anchor => $blog_id){
$anchor_url = 'http://www.site.com';
mysql_query("INSERT INTO anchors (blog_id, anchor_url, anchor) VALUES ('$blog_id', '$anchor_url', '$anchor')");
}
mysql_close($connect);
?>
泰非常多,這裏是表結構:
CREATE TABLE `anchors` (
`id` int(11) NOT NULL auto_increment,
`blog_id` text,
`anchor_url` text,
`anchor` text,
PRIMARY KEY (`id`),
FULLTEXT KEY `posttitle` (`blog_id`,`anchor_url`,`anchor`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8
爲了上帝的愛,不要用所有這些查詢來殺死你的數據庫。創建一個包含所有數據('INSERT INTO tbl(x,y)VALUES((x1,y1),(x2,y2),(...))'的大型組合INSERT語句,或至少使用準備好的陳述 – kba
你好克里斯蒂安,我是一個新手,你說不要使用foreach循環嗎?非常好 – webmasters
是的,它相當於將一堆紙從一張表移動到另一張表,而不是一次一頁 – kba