How does php obtain the array in the variable and assign it to the variable? PHPcode: How do I perform the following actions when $ products1001: (There is one execution statement) $ db-& gt; query (& quot; UPDATE {$ _ pre} contentSETstorages php how can I retrieve the array in the variable and assign the value to the variable?
PHP code
How can I perform the following actions when $ products = 100 = 1: (one execution statement exists at this time) $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '"); how can I perform the following actions when $ products = 100 = 1,104 = 3: (two statements are executed at this time) $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-3 WHERE id = '000000 '"); when $ products = 100 = 1,104 = 8,204 = 4,243 = 2,690 = 1, how do I perform the following actions: (five statements are executed at this time) $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-8 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-4 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-2 WHERE id = '000000 '"); $ db-> query ("UPDATE {$ _ pre} content SET storage = storage-1 WHERE id = '000000 '");
------ Solution --------------------
PHP code
$products ='100=1,104=8,204=4,243=2,690=1';foreach(explode(',',$products) as $v){ $t=explode('=',$v); $db->query("UPDATE {$_pre}content SET storage=storage-{$t[1]} WHERE id='{$t[0]}'");}