I have a loop of code that creates SQL queries from a CSV file. Below is a very simplified version of the loop:
$fh = fopen($outfile, "r");
while (list($model, $quantity) = fgetcsv($fh, 1024, ",")) {
$sql = "update products p set p.products_quantity = '" . $quantity . "' where p.products_mfgmn = '" . $model . "'";
tep_db_query($sql);
}
The problem is that the csv file has over 80,000 lines and many of the lines have multiple entries for $model. The CSV file may have 50 entries while the MySQL database may have 500 entries for the $model. This means a query that updates 500 entries will be run 50 times which makes this code EXTREMELY inefficient and slow. Is there a way to make sure only one of each SQL runs. I bet there is a fairly simple way to do it, but I'm still very new to PHP.