4

I have three columns in a table named id, wishlist_id and type and I want to fetch wishlist_id according to the type field into an array

I am using the follwing code:

$wishlistId = $mysql->getColumn("SELECT `wishlist_id` FROM `customer_wishlists` WHERE `type`='wishlist'");
print_r($wishlistId);

It is giving me only repeated value

1 Answer 1

14

Try this

$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql        = "SELECT wishlist_id FROM `customer_wishlists` WHERE `type`='wishlist'";
$rows       = $connection->fetchAll($sql); 
print_r($rows);

OR

$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql        = "SELECT `wishlist_id` FROM `customer_wishlists` WHERE `type` LIKE 'wishlist'";
$rows       = $connection->fetchAll($sql); 
print_r($rows);
2
  • Unable to get result if added the where clause. Without where clause works fine.
    – Ck Maurya
    Feb 22, 2017 at 10:28
  • Then something is wrong with your WHERE. Maybe you need to escape stuff. @CkMaurya
    – Max
    Jul 25, 2017 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.