Gina Co Gina Co - 4 months ago 5
PHP Question

I want to delete a record in my sql with array as inputs with two where statement

I want to delete a record in my sql with array as inputs with two where statement. I cant find a statement like this one...

"DELETE FROM perpetualinventory WHERE productID= ".implode(',',$productID)" && expiryDate=".implode(',',$expiryDate);


for the suggested answer

"DELETE FROM perpetualinventory WHERE productID IN (".implode(',',$productID)") AND expiryDate IN (".implode(',',$expiryDate).")";



syntax error, unexpected '") AND expiryDate IN ("' (T_CONSTANT_ENCAPSED_STRING)

Answer

This code should work :

DELETE FROM perpetualinventory WHERE productID IN ('".implode($productID,"', '")."') AND expiryDate IN ('".implode($expiryDate,"', '")."')";

Explanation :

DELETE FROM table
WHERE column IN ('".
    implode($array, "'separator'") // separator = ', ' for arrays. Be careful for space after the comma.
."')
AND ...
Comments