0

I have the following query, the AND state = 1 is being ignored, i get all the states instead of only what is equal to 1. Where is my mistake here?

$query = "
                SELECT state, id, variable, name, {$columns->specific}, {$columns->allExcept}, {$columns->specificExclude}, {$columns->relationAllExcept}, repeatable

                FROM #__epc_fieldsgroups
                WHERE FIND_IN_SET({$relationRecordId}, {$columns->specific})

                OR {$columns->allExcept} != 0
                AND FIND_IN_SET({$relationRecordId}, {$columns->allExcept}) = 0

                AND state = 1
                ORDER BY ordering
             ";
Danigoodw
  • 379
  • 3
  • 10

1 Answers1

0

you need to define start and end of AND using parentheses

$query = "
                SELECT state, id, variable, name, {$columns->specific}, {$columns->allExcept}, {$columns->specificExclude}, {$columns->relationAllExcept}, repeatable

                FROM #__epc_fieldsgroups
                WHERE FIND_IN_SET({$relationRecordId}, {$columns->specific})

                OR {$columns->allExcept} != 0
                AND {FIND_IN_SET({$relationRecordId}, {$columns->allExcept}) = 0}

                AND {state = 1}
                ORDER BY ordering
             ";
phpdroid
  • 1,642
  • 1
  • 18
  • 36