Custom Table – How to Fetch Data with Select Query

customtable

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

Best Answer

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);
Related Topic