title: Adding a database result to an array and fill another respective array to the same database table
body: <p>I have written a program to insert an array in all the rows of a column in a database table with respect to already filled column in the same database same table. </p>
  
  <p>But it doesn't seems to work properly. Please tell me where I am going wrong! </p>
  
  <pre><code>$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&lt;$count;$counter++)
  {
  
  $query= "INSERT INTO `TABLE` (`B`) VALUES ('" . $value . "') WHERE A= $row[$counter] ";
  
  $insert_col= mysql_query($query);
  
  echo $query;
  echo '&lt;br/&gt;&lt;br/&gt;';
    }} 
  
  } 
  </code></pre>
  
  <p>Where <code>$output</code> is an array contains the array value as follows:</p>
  
  <pre><code>$output[0]= RD 3.56 , $output[1]= RD 5.56 , $output[2]= RD 4.86 
  </code></pre>
  
  <p>When I run my program, to check my the query .. the output comes like this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Please help! i am going mad with this bug in my program for almost more than a week.</p>
  
  <p>The output should look like this</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>The problem here is <code>$row</code> value is repeated 6 times for all the <code>$output</code> values. How can I solve the problem?</p>
  
  <p>And after lot of trials, I got to know that the problem is in calling the arrays. So, if anyone can tell me how to call the two arrays at the same time w.r.t the code written above, I would be very grateful.</p>