If we want to get specific fields means we can’t get. Normal magento collection give all the main table collection like bellow.
Code:
$value = Mage::getModel(‘customer/customer’)->getCollection()
->addFieldToFilter(’email’, array(‘neq’ => NULL))
->addFieldToFilter(‘created_at’, array(‘neq’ => NULL))
->addAttributeToSelect(’email’)->getdata();
echo “<pre>”;
print_r($value);
Answer:
Array
(
[0] => Array
(
[entity_id] => 2025
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => 12234455515-29
[has_options] => 0
[required_options] => 0
[created_at] => 2012-06-14 11:04:14
[updated_at] => 2012-10-04 11:12:49
[zone_logic] => RZ1
)
)
So that we need to over come the above query need to do like below can get only specific fields value.
Code:
$collection = Mage::getModel(‘customer/customer’)->getCollection();
$collection->getSelect()
->reset(Zend_Db_Select::COLUMNS)
->columns(’email as cust_email’)
->columns(‘created_at as create_time’);
//echo $collection->getSelect()->__toString();
echo “<pre>”;
print_r($collection->getData());
Answer:
Array
(
[0] => Array
(
[cust_email] => test@test.com
[create_time] => 2012-12-14 08:36:34
)
)
Magento provide addFieldToSelect() fumctionality. Use below code to get specific field.
$Collection = Mage::getModel(‘customer/customer’)->getCollection();
$Collection->addFieldToSelect(’email’);
Thanks Neeraj.