0

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']);
        }
    }
    print_r($dealerIds);
    die;
    $dealerModel = Mage::getModel('dealers/dealer');
  • please share your current code – Shoaib Munir May 9 at 10:01
  • I added the code above – NAVEEN KUMAR May 9 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 at 10:02
1

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.

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.