HI,
I want to import data from csv files into more than one tables in php.i want to import the data into selected tables in the same database.
Here is the output:
1;2006-12-05;Sony;tv plasma;5;4500.00;4550.00;
aaaaaaaaa;12;sony;tv.jpeg;http://;www.;57.00;
The format of each line is:
{products_status},{products_date_available},{manuf acturers_id},{products_name},{products_tax_class_i d},
{products_price},{products_price_gross},{products_ description},{products_quantity},{products_model},
{products_image},{products_url},{products_weight}
Here is my code:
<?
$fcontents = file ('./test.csv');
# expects the csv file to be in the same dir as this script
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
echo "$line<BR>";
$arr = explode(";"", $line);
echo "$arr";
$sql = "insert into tablename values (". implode("'", $arr).")";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
}
?>
Thanks