cancel
Showing results for 
Search instead for 
Did you mean: 

Update multiple records in a single query

Update multiple records in a single query

Hello everyone,

 

I have one problem regarding update records. I have different IDs in table and depending on that data of that records should be updated. Currently I perform this using loop and pass the ID each time and update details. 

 

Here is my code:

foreach ($cart->getAllVisibleItems() as $item) {

if (!empty($whishlist_product_array[$item->getProductId()])) {

$wishlist_item_id = $whishlist_product_array[$item->getProductId()]['wishlist_item_id'];

$qty = new Zend_Db_Expr('qty+' . $item->getQty());
$update_data = array('qty' => $qty);
Mage::getModel('wishlist/item')->load($wishlist_item_id)->addData($update_data)->setWishlistItemId($wishlist_item_id)->save();

} else {

$insert_data = array(
array('wishlist_id' => $wishlist->getId(),
'product_id' => $item->getProductId(),
'store_id' => Mage::app()->getStore()->getStoreId(),
'added_at' => date('Y-m-d H:i:s'),
'qty' => $item->getQty(),
'created_at' => date('Y-m-d H:i:s'),
'wishlist_name' => $wlistname)
);

}

$wlisturl = "<a href='" . Mage::getBaseUrl() . "savecart/' style='color:#585858;font-weight:bold;font-size:12px;text-decoration: underline;'>" . $wlistname . "</a>";
$message = Mage::helper('wishlist')->__("%s has been added to your save cart &nbsp; %s", $item->getProduct()->getName(), $wlisturl);
$session->addSuccess($message);
}

Here you can see the update query in the loop. What if I want to update those details in a single query. It is possible in MySQL query.

 

Kindly reply if anyone found the answer.

 

Regards,

Anand Solanki