1

I want to get data of the custom table, this is my code

$address = Mage::getModel ( 'shippingaddresses/shippingaddresses' )->getCollection()->addFieldToSelect('*')->addFieldToFilter(
                   array(
                             array("account_id",["eq"=>$customerNumber]),
                             array("account_name",["like"=>"%".$customerName."%"]),
                             array("shipping_city",["like"=>"%".$customerCity."%"]),
                             array("shipping_postal_code",["like"=>"%".$customerCode."%"])
                   )
        );

My error

Column not found: 1054 Unknown column 'account_id.Array' in 'where clause', query was: SELECT `main_table`.* FROM `commercers_shippingaddresses` AS `main_table` WHERE ((`account_id`.`Array` = '') OR (`account_name`.`Array` = '') OR (`shipping_city`.`Array` = '') OR (`shipping_postal_code`.`Array` = ''))";i:1;s:2143:

UPDATE

I tryed this code but this has a problem. I need it find AND.

$address = Mage::getModel ( 'shippingaddresses/shippingaddresses' )
                  ->getCollection()
                  ->addFieldToFilter(['account_id', 'account_name', 'shipping_city', 'shipping_postal_code'],
                   [
                       ['eq' => $customerNumber],
                       ['like' => "%".$customerName."%"],
                       ['like' => "%".$customerCity."%"],
                       ['eq' => $customerCode]

                   ]);
2
  • Please check$customerNumber getting in array. Commented Aug 16, 2019 at 4:42
  • Is this your custom table? Commented Aug 16, 2019 at 4:44

3 Answers 3

2
$address = Mage::getModel('shippingaddresses/shippingaddresses')->getCollection();

$address->getSelect()->where("account_id = $customerNumber and account_name like '%$customerName%' and shipping_city like '%$customerCity%' and shipping_postal_code like '%$customerCode%'");
2
  • Thank you so much, it work for me <3 have a nice day Sweety Masmiya
    – Brian N
    Commented Aug 16, 2019 at 5:17
  • Thank you :-) Happy codding. Commented Aug 16, 2019 at 5:27
0

Please try with below code to try with array

$address = Mage::getModel('shippingaddresses/shippingaddresses') ->getCollection() ->addFieldToSelect('*') ->addFieldToFilter( array('account_id', 'account_name', 'shipping_city', 'shipping_postal_code'), array( array('eq' => $customerNumber), array('like'=> '%' . $customerName . '%'), array('like'=> '%' . $customerCity . '%'), array('like'=> '%' . $customerCode . '%') ) );
1
  • please check update question
    – Brian N
    Commented Aug 16, 2019 at 4:55
0

Try this:

$address = Mage::getModel('shippingaddresses/shippingaddresses')
            ->getCollection()
            ->addFieldToSelect('*')
            ->addFieldToFilter('account_id', ['eq' => $customerNumber])
            ->addFieldToFilter('account_name', ['like'=> '%' . $customerName . '%'])
            ->addFieldToFilter('shipping_city', ['like'=> '%' . $customerCity . '%'])
            ->addFieldToFilter('shipping_postal_code', ['like'=> '%' . $customerCode . '%']);
6
  • anh check lại câu hỏi giúp em với, hình như nó search bằng OR
    – Brian N
    Commented Aug 16, 2019 at 4:55
  • Mình update lại câu tra lời rồi bạn nhé.
    – Toan Tam
    Commented Aug 16, 2019 at 5:03
  • Code mới chạy ko bạn?
    – Toan Tam
    Commented Aug 16, 2019 at 5:15
  • dạ không đúng ý em anh ơi, nhưng mà code của bạn đẹp Sweety Masmiya ổn rồi anh ơi, thanks anh nhé <3
    – Brian N
    Commented Aug 16, 2019 at 5:17
  • Ukm. hihi. Lạ nhỉ?
    – Toan Tam
    Commented Aug 16, 2019 at 5:17

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.