$connection = $this->getConnection();
$select = $connection->select();
$select = $model->getCollection()
   ->from($this->getDbPrefix() . 'name_table', '*')
   ->where('result', ' likes%');
   return (int)$objectManager->fetchOne($select);

I want SELECT COUNT (*) FROM name_table WHERE result LIKE 'likes%' to be executed, and a numeric value is displayed on the page.How do I do it? I'm a beginner. I'll be very grateful for your help!

2 Answers 2


Your code wrong on two cases.

If $model a model class then $model->getCollection()->select() have to chanages $model->getCollection()->getSelect(). athat is wrong.

Also, (int)$objectManager->fetchOne($select) wrong.

You can use collection

$model->getCollection()->addAttributeToFilter('result', ['like' => 'likes%']);


Try below code

$collection->addAttributeToFilter('name', array(
    array('like' => '% '.$needle.' %'), //spaces on each side
    array('like' => '% '.$needle), //space before and ends with $needle
    array('like' => $needle.' %') // starts with needle and space after

Passing the second parameter as an array of arrays will concatenate the conditions using OR

I hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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