Negative Except Regex Filter with Database?
Negative Except Regex Filter with Database?
Hey everyone,
I'm attempting to get a functioning negative regex filter working with my table that pulls data from a mySQL database.
I've attempted to get the script from here: http://datatables.net/forums/discussion/4345/negative-exclude-except-search-example/p1 working, but out of the box I have found that regex doesn't seem to work at all with external databases. Though I've seen some regex scripts made to work with external sources, I haven't been able to find anything about getting something like this working.
Does anyone have some advice or pointers for getting me going in the right direction to get this working?
I'm attempting to get a functioning negative regex filter working with my table that pulls data from a mySQL database.
I've attempted to get the script from here: http://datatables.net/forums/discussion/4345/negative-exclude-except-search-example/p1 working, but out of the box I have found that regex doesn't seem to work at all with external databases. Though I've seen some regex scripts made to work with external sources, I haven't been able to find anything about getting something like this working.
Does anyone have some advice or pointers for getting me going in the right direction to get this working?
This discussion has been closed.
Replies
your server side script can look for patterns in the search strings, like the negative operator, and put together your SQL WHERE clause appropriately.
CORRECTION: looks like MySQL has REGEXP functionality: http://www.go4expert.com/forums/showthread.php?t=2337
Do you maybe have some guidance as to how I could pass the command to my server side script to detect it? The SQL string should be no problem, I'm just not sure how the fnFilter function passes data to it.
Edit:
Thanks for the update clarifying regexp functionality, but it still doesn't help that I don't know how data is passed to the server side script. I would greatly appreciate any help with that!
see http://datatables.net/ref#fnServerData or http://datatables.net/usage/server-side, and Allan's sample server side code at http://datatables.net/release-datatables/examples/server_side/server_side.html
for column-specific filter, a parameter named sSearch_{i} will be set, where {i} is the column index. if you have set reg exp in the fnFilter, bRegex_{i} should be set "true"
if you detect bRegex_{i} and sSearch_{i} are set, you can add to the WHERE clause of your SQL using the REGEXP operator in MySQL. [note: I'm not testing this code. I'll leave debugging to you]
[code]
for ( $i=0 ; $i
The code is still pretty rough at the moment, but it functions just fine. I'll update the post when I get it cleaned up more.
[code]/* Individual column filtering */
for ( $i=0 ; $i