我不能比較這陣mysql數據庫值進行比較數組值與PDO
$products = [];
foreach (array_keys($match[2]) as $idx)
{
$tagliaprodotto = rtrim(substr($match[2][$idx],1));
$tagliaquantita = ltrim($match[3][$idx],'0');
$products[] = [
'product' => $tagliaprodotto,
'quantity' => $tagliaquantita,
'terminal' => $match[4][$idx]
];
}
與數據庫內的值的值!我應該這樣做嗎?
我想比較,我有在數據庫內的元素與數組的值,使一些if爲:
- 如果產品不存在於數據庫中:
INSERT INTO table (product, quantity, terminal, date) VALUES (:product, :quantity, :terminal, NOW())
- 如果數據庫記錄完美匹配:產品,數量和終端:Do nothing
- 如果數據庫記錄包含:相同產品但數量不同和/ o [R終端:
UPDATE table SET quantity=:quantity, terminal=:terminal
https://stackoverflow.com/questions/23305300/check-if-username-exists-pdo –
我沒有單個變量$ user ='userName'; – Squalo
這是演示例子,所以你可以更新你的代碼,就像它 –