In my mysql database I get ONLY the records for id 26, 16, 17, 18, 19, 22, 23, 24. Why is that, is there any error in my code? I don;t have a clue, please help:(
<?
$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);
?>
Ty very much, here is the table structure:
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
Check whether the query actually can be executed.
Furthermore, what is the table structure like?
SHOW CREATE TABLE anchors;will help you. If you have a unique or primary key set, the value really needs to be unique and duplicates fail with an error.Edit: The problem is not within the script, but within the data. In order to have the data in PHP, the storage needs to be adjusted.