SiREKT
SiREKT

Reputation: 37

Multiple Variable in one SQL Like

I searched a lot and cannot find my answer. I'm trying to include 2 variable in my like statement to match a date that wasn't formatted correctly in a database I'm working on.

I need to:

Select count(*) as ABC 
    from database 
    where active like '1' 
        and agent = '$Employeestringid' 
        AND time LIKE '%$FilterMonth_%_$queryyear'"

The part that is currently not working is: '%$FilterMonth_%_$queryyear'

I need it to work and match a date formatted like: '9:10:31 PM Fri, May 20th 2016' by only capturing MONTH and YEAR.

Upvotes: 0

Views: 30

Answers (2)

gen_Eric
gen_Eric

Reputation: 227210

When interpolating your variables in the string, PHP reads the _ as part of the variable name.

You need to use {} to prevent this behavior:

$query = "Select count(*) as ABC 
    from database 
    where active like '1' 
        and agent = '$Employeestringid' 
        AND time LIKE '%{$FilterMonth}_%_{$queryyear}'";

Upvotes: 1

Mojtaba
Mojtaba

Reputation: 5004

Remove the underscores

'%$FilterMonth%$queryyear'

Upvotes: 0

Related Questions