1
<?php
$connection = $this->getConnection();
$select = $connection->select();
$select = $model->getCollection()
   ->select()
   ->count()
   ->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!

0

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%']);

0
2

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, privacy policy and cookie policy

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