Using if in where clause with datatable editor
Using if in where clause with datatable editor
![kharismatics](https://secure.gravatar.com/avatar/c351529030112d7c0c79fce12afd1474/?default=https%3A%2F%2Fvanillicon.com%2Fc351529030112d7c0c79fce12afd1474_200.png&rating=g&size=120)
How can i use if condition with WHERE CLAUSE of datatable editor
here is the query example
SELECT
*
FROM
tablename
WHERE IF(category=1, rule = 1, rule = 2)
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
->where( function ( $q ) {
$q
->where( "IF(category=1,rule = 1,rule = 2)", "if(1=1,1,0)", "=", false );
})
im using this right now but i think there is a better way![:neutral: :neutral:](https://datatables.net/forums/resources/emoji/neutral.png)
I think the only better way would be to use a VIEW. There aren't any methods in the database abstraction to apply
if
conditions in the SQL.Allan
thanks @allan for the suggestion![:blush: :blush:](https://datatables.net/forums/resources/emoji/blush.png)