2012-08-13 21 views
-2

行,所以我有一個PHP陣列看起來MySQL的UPDATE多行,但是單個列不同的值從數組提取

array('somehash' => 'someotherhash', 'somehash2' => 'someotherhash2');

這裏somehash = producthash和someotherhash = tohash

$db->query('UPDATE sometable SET status = '.self::STATUS_NOT_AVAILABLE.', towhere = '.self::TO_WHERE.', '. 
        .'tohash = WHEN or IF or ??? and how ?, '. 
        .'WHERE status = '.self::STATUS_AVAILABLE.' AND '. 
        .'producthash IN (' . implode(',' , $prodarray) . ')') or $db->err(__FILE__,__LINE__); 

所以在上面的查詢中,我想要tohash的值通過producthash從php數組中取得mysql字段

tohash = IF(producthash IN '.$prodarray.', $prodarray['producthash'] , whatever)

ofcourse上述IF不會工作的原因我沒有在$prodarray['producthash']

任何人producthash值知道解決的辦法,因爲我有數組中的超過1000米的價值觀和不希望運行一千更新

,因爲該表的唯一鍵是基於3場,我不具有所有三個字段值,而這樣做更新INSERT INTO對重複鍵不在這個原因可能。

回答

0

子查詢?

UPDATE ... 
WHERE ... producthash in (SELECT * FROM products) 

這將工作,只要你不從你更新的同桌選擇 - MySQL不允許,沒有變通方法。

相關問題