0

How can I write the follow sql query in MeDoo???

SELECT * FROM lockers WHERE Active = 1 AND GymID = " . $gimid . " AND ForMale = " . $male . 
                    ($filter ? " AND Locker LIKE '%" . $filter . "%'" : "")

The problem for me is the conditional LIKE.

$total = $this->db->count('lockers', 
     ['AND' => [
          'Active' => 1, 
          'GymID' => $gimid, 
          'ForMale' => $male
     ]]
);

Some suggestion???? Thanks a lot!!!

Silver Lora
  • 107
  • 1
  • 9
  • Does this answer your question? [LIKE operator in medoo](https://stackoverflow.com/questions/38461660/like-operator-in-medoo) – gre_gor Dec 17 '19 at 19:10
  • Thank you, but are differents statements... in the example below the LIKE always will appear, in my case, if condition FALSE, the LIKE will not included. – Silver Lora Dec 17 '19 at 20:07

1 Answers1

1

Finally, I solved it in the follow way:

// getting locker's total
$total = $this->db->debug()->count('lockers', [
    'AND' => [
        'Active' => 1, 
        'GymID' => $gimid, 
        'ForMale' => $male,
        'Locker[~]' => $filter ? $filter : '' //<- LIKE with empty string shows all
    ]
]);
Silver Lora
  • 107
  • 1
  • 9