I have a huge table from one mysql db, I want to create a new table in different mysql db and copy 3 columns from the huge one. To do that, I wrote the following code:
$result = mysql_query("SELECT * FROM huge_table", $hugeDB);
$count = mysql_result($result, 0);
$iterations=ceil($count/500);
for($i=1; $i<=$iterations; $i++)
{
$start = ($i-1)*500;
$query = mysql_query("SELECT col1, col3, col6 FROM huge_table LIMIT $i, 500", $hugeDB);
$results = array();
$j = 0;
while($result = mysql_fetch_array($query)) {
$result[$j]= '('.$result['col1'].', '.$result['col3'].', '.$result['col6'].')';
$j++;
}
print_r($results);
$a = mysql_query("INSERT INTO less_huge_table (col1, col3, col6) VALUES ".implode(',', $results), $localDB);
if(!$a) die(mysql_error()."\n");
}
But then the output is:
Unknown column 'BTFG' in 'field list'
Where BTFG is the array’s first element’s item:
(2007-01-03, BTFG, 23.0481)
I think I’m making a little mistake but I couldn’t catch.
How should I solve this problem ?
Thanks
Your array is
$resultnot$resullts. You declared array with$resultsthen assigned values in$resultand in insert you are using$resultswhich is blank.it should be
BTW what is
$j++not used anywhere else.EDIT:
quote char and string values properly:
change here :