lawrence_dev
asked on
PHP PDO How do I correctly remove record using DELETE FROM?
Every 15 minutes we update our stock quantity. Is this the proper way to delete a product if the product becomes out of stock? Please note: There is a master download that updates all products every morning.
$conn->query("DELETE FROM `oc_product` WHERE quantity == 0");
$conn->query("DELETE FROM `oc_product` WHERE quantity == 0");
$filename="http://datadownloads.**********.net/data/count.csv";
//rebs,rebe,spec,os&time= . $time . ";
//open the file
$handle = fopen($filename, "r");
//this is what causes it to skip
fgetcsv($handle,",");
//begin looping through the lines
while (($data = fgetcsv($handle, ",")) !== FALSE)
{
// loop all column values and escape special characters
foreach ($data as $key => $value){
$data[$key] = $value;
}
//Update stock
$conn->query("UPDATE `oc_product` SET quantity = $data[3] WHERE product_id = $data[0]");
//echo $data[0]." ".$data[3]."<BR>";
//Delete Out Of Stock Items from Database
$conn->query("DELETE FROM `oc_product` WHERE quantity == 0");
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.