here is a mysql database named: example which has a table named: products it have fields: products_model and products_image. the model field is unique.
now i have a csv file named data.csv. which have two column products_model and products_image.i use the following code. but it doesn’t update the data of the database.what’s wrong with my code?
$fp = fopen("data.csv","r");
$length = 4096;
$fildDelineate = ',' ;
$dbhost="localhost";
$dbname="example";
$dbuser="root";
$dbpass="123";
$link = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
$databasetable = 'products';
$counter = 1;
while($line = fgetcsv($fp,$length,$fildDelineate)){
foreach($line as $key=>$value){
$importSQL = "update products set products_image = '".$lineArray[1]."' where products_model = '". $lineArray[0].""";
mysql_query($importSQL) or die(mysql_error());
}
$counter++;
}
fclose($fp);
it’s ok now. thank you. why your code don’t use foreach loop? the counter = 1 is out of the while loop. i don’t know why you don’t use foreach. thank u