I am trying to update Qty column where suppliers_stock_code = '" . $itemno . " but products_model does not contain '--'
I have tried
$sql = "UPDATE products set suppliers_qty = '" . $qty . "' (SELECT suppliers_stock_code, products_model from products where products_model NOT LIKE '%--%' and products_status = '1' and suppliers_stock_code = '" . $itemno . "')";
But this does not appear to insert the values can anyone see what is wrong with this line?
I have also tried
$sql = "update products set suppliers_qty= '" . $qty . "' where " . PRODUCTS_MODEL . " = '" . $selected['products_model'] . "' and " . SUPPLIERS_MODEL . "= '" . $itemno . "' and " . PRODUCTS_MODEL . " NOT LIKE '%--%'";
This works but takes to long to execute so was hoping to pre select the items to update.
Heres the full script maybe there is a better (faster) way of doing it?
<?php
$working_dir = '../feeds/csv';
$local_file = 'test.csv';
$type_sep = ",";
$item_pos = 2;
$qty_pos = 3;
$item_pos -= 1;
$qty_pos -= 1;
chdir($working_dir);
$handle = fopen($local_file, 'w');
require('includes/configure.php');
require('includes/functions/database.php');
tep_db_connect_script() or die('Unable to connect to database server!');
$lines = file($local_file);
foreach ($lines as $line) {
$items = explode ($type_sep, $line);
$itemno = $items[$item_pos];
$qty = $items[$qty_pos] * 0.10;
$sql = "UPDATE products set suppliers_qty = '" . $qty . "'
WHERE products_model NOT LIKE '%--%'
AND products_status = '1' AND suppliers_stock_code = '" . $itemno . "'";
$result = mysql_query($sql);
}
}
tep_db_close_script();
echo 'Finished and closed database connection';
?>