1

I am using grid serialization in my custom module grid.

I want to filter data using student_ids.

I have current student id.

In database student_ids save multiple student id for Ex. 1,2,3.

Now i want to filter grid current student id exists in student_ids.

I am trying this

$currentStudentId = $this->getRequest()->getParam('id');
    $collection = Mage::getModel('example/data')->getCollection()
                ->addFieldToFilter('student_ids',array('like' => '%,'.$currentStudentId));

but using this i can't get proper data because string is like this 1,2,3 here so many possibility so i can't use this please give me solution

[EDIT]

enter image description here

3
  • can you please show the database table data in screenshot.
    – Amit Bera
    May 29, 2015 at 5:54
  • you can use array('in' => array(1,2,3)) instead of array('like' => '%,'.$currentStudentId)
    – Amit Bera
    May 29, 2015 at 5:55
  • not possible $currentStudentId is single value like 1 or 2 or 3. student_ids is 1,2,3 and check my update
    – ND17
    May 29, 2015 at 5:58

1 Answer 1

2

you can use finset sql cluse

$currentStudentId = $this->getRequest()->getParam('id');
        $collection = Mage::getModel('example/data')->getCollection()
         ->addFieldToFilter('student_ids',array("finset"=>$currentStudentId);

basically this clause use in magento when we have multiple selection in any attribute

hope it will work for you.

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.