I am new to magento. How can I use where in clause in magento 1. I have array of ids and I want rows from those ids from database. Please help me here.

$stateDealersCollection = $stateDealerModel->getCollection()->distinct(true)->addFieldToFilter('state_id', array('eq' => $data['state_id']))->addFieldToSelect('dealer_id')->getData();
    $dealerIds = [];
    foreach ($stateDealersCollection as $dealer)
        if (!in_array($dealer['dealer_id'], $dealerIds))
            array_push($dealerIds, $dealer['dealer_id']);
    $dealerModel = Mage::getModel('dealers/dealer');
  • please share your current code – Shoaib Munir May 9 '19 at 10:01
  • I added the code above – NAVEEN KUMAR May 9 '19 at 10:01
  • I have three tables states, dealers and state_dealers. I want on select of state i need dealers list. I also tried to use join here but not able to write correct syntax. If you can help me with this, that would be awesome. – NAVEEN KUMAR May 9 '19 at 10:02

just use dealers id array $dealerIds in addFieldToFilter with in command like this:

$dealerModel = Mage::getModel('dealers/dealer');
$dealerModel->addFieldToFilter('id', array('in' => $dealerIds));

Hope you find your solution.

| improve this answer | |
  • it worked. Thanks – NAVEEN KUMAR May 9 '19 at 10:09
  • Good to hear that. welcome :) – Shoaib Munir May 9 '19 at 10:10

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.