1
$collection = Mage::getModel('saplocation/saplocation')->getCollection()
                    ->addFieldToFilter('location', array('like' => '%'.$location.'%'));

foreach ($collection as $values) {
    array_push($returnjson, $values['pincode']);
}
echo json_encode($returnjson);

How to get the unique values from magento table, i have tried distinct but it is not working. please help

2
$return = array();
$collection = Mage::getModel('saplocation/saplocation')->getCollection()
                    ->addFieldToFilter('location', array('like' => '%'.$location.'%'));
foreach ($collection as $values) {
    $return[$values['pincode']] = $values['pincode'];
}
echo json_encode(array_values($return));
  • 1
    You are awesome Marius. – Naveenbos Feb 1 '16 at 9:36
1
        $returnjson = array();

        $collection = Mage::getModel('saplocation/saplocation')->getCollection()
                    ->addFieldToFilter('location', array('like' => '%'.$location.'%'));
                    //->addFieldToFilter('location', $location);
        foreach ($collection as $values) {

            $returnjson[$values['pincode']] = $values['pincode'];
        }
        echo json_encode($returnjson);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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