Question

<?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!

Was it helpful?

Solution

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

OTHER TIPS

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top