Conditional Where Filters (using DataTables PHP Libraries and SQLSRV)
Conditional Where Filters (using DataTables PHP Libraries and SQLSRV)
I'm using the DataTables PHP libraries that came with Editor to connect to our MS SQL server to provide data for my tables.
Up until today I've been using SQL wildcards ('%') to filter data...
if (isset($_GET['nationalityID']) == true) {
$nationalityID = ($_GET['nationalityID']);
} else {
$nationalityID = '%';
}
...
->where('Applicant.NationalityID', $nationalityID, 'LIKE')
..but have run into issues where rows with NULL entries are not returned when using the wildcard. I'm not good with object-oriented programming so I'm struggling with the necessary coding syntax, but I'm trying to get my ->where filters to activate only if the variables posted to the PHP from AJAX actually have values, so I no longer need to use the wildcards. Can anyone help me with this?
This question has an accepted answers - jump to answer
Answers
I've tried removing the chaining from my Editor object instance in my PHP to see if I can conditionally add my SQL 'Where's to it using IF statements on my variables, but it seems to only ever return any data to the browser when using the "chained" method:
If I change this code so that each method begins with $data and ends with a semicolon then the browser just sits there forever waiting for data, so I'm guessing I can't go about it this way either...
I think breaking the chain is the correct way to do this.
Allan
edit - Missed out the
$data =
.Thanks Allan. I think I need to work on my OOP skills..!