我编写了一个程序,用于在数据库表中的列的所有行中插入一个数组,该数组相对于同一个数据库同一个表中已填充的列。
但它似乎不能正常工作。请告诉我哪里出错了!
$query = $sql = "SELECT A FROM `table`";
$result1 = mysql_query($query);
while ($row = mysql_fetch_row($result1)) {
foreach($output as $value){
$count=sizeof($value);
for($counter=0;$counter<$count;$counter++)
{
$query= "INSERT INTO `TABLE` (`B`) VALUES ('" . $value . "') WHERE A= $row[$counter] ";
$insert_col= mysql_query($query);
echo $query;
echo '<br/><br/>';
}}
}
其中$output
数组包含数组值如下:
$output[0]= RD 3.56 , $output[1]= RD 5.56 , $output[2]= RD 4.86
当我运行我的程序时,检查我的查询..输出如下:
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.144') WHERE A= 3r_1
INSERT INTO `TABLE` (`B`) VALUES (' RD: 2.436') WHERE A= 3r_1
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.624') WHERE A= 3r_1
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_1
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_1
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_1
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.144') WHERE A= 3r_2
INSERT INTO `TABLE` (`B`) VALUES (' RD: 2.436') WHERE A= 3r_2
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.624') WHERE A= 3r_2
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_2
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_2
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_2
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.144') WHERE A= 3r_3
INSERT INTO `TABLE` (`B`) VALUES (' RD: 2.436') WHERE A= 3r_3
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.624') WHERE A= 3r_3
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_3
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_3
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_3
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.144') WHERE A= 3r_4
INSERT INTO `TABLE` (`B`) VALUES (' RD: 2.436') WHERE A= 3r_4
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.624') WHERE A= 3r_4
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_4
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_4
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.60') WHERE A= 3r_4
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.144') WHERE A= 3r_5
INSERT INTO `TABLE` (`B`) VALUES (' RD: 2.436') WHERE A= 3r_5
INSERT INTO `TABLE` (`B`) VALUES (' RD: 1.624') WHERE A= 3r_5
请帮忙!我对我的程序中的这个错误快一个多星期了。
输出应如下所示
INSERT INTO 'TABLE' SET B = ' RD: 1.144' WHERE A = '3r_1'
INSERT INTO 'TABLE' SET B = ' RD: 2.436' WHERE A = '3r_2'
INSERT INTO 'TABLE' SET B = ' RD: 1.624' WHERE A = '3r_3'
INSERT INTO 'TABLE' SET B = ' RD: 1.560' WHERE A = '3r_4'
INSERT INTO 'TABLE' SET B = ' RD: 1.560' WHERE A = '3r_5'
INSERT INTO 'TABLE' SET B = ' RD: 1.560' WHERE A = '3r_6'
这里的问题是$row
值对所有值重复 6 次$output
。我该如何解决这个问题?
经过大量试验,我知道问题在于调用数组。因此,如果有人能告诉我如何使用上面编写的代码同时调用两个数组,我将不胜感激。