Adding a "Where" clause in PHP query
Adding a "Where" clause in PHP query
studio6000
Posts: 7Questions: 0Answers: 0
Hi,
I installed the server side example and that is working fine. See here:
http://frumtown.com/listings/server_side.php
I want to filter the MySQL in the server_processing.php script . I managed to do that by adding:
AND custom_7 = 2
to the $where variable.
However, when I change that to
AND custom_7 = " . $_GET['custom_7']
and then go to http://frumtown.com/listings/server_side.php?custom_7=2
It doesn't work.
So I tried the custom_vars script as well thinking that would work, but it doesn't either.
I added this
aoData.push( { "name": "custom_7", "value": "2" } );
What am I doing wrong? I need to be able to control the MySQL query since users will be searching by a form and non-relevant rows should not appear.
Hope this all makes sense.
Thanks in advance for any help you can give.
Michelle
I installed the server side example and that is working fine. See here:
http://frumtown.com/listings/server_side.php
I want to filter the MySQL in the server_processing.php script . I managed to do that by adding:
AND custom_7 = 2
to the $where variable.
However, when I change that to
AND custom_7 = " . $_GET['custom_7']
and then go to http://frumtown.com/listings/server_side.php?custom_7=2
It doesn't work.
So I tried the custom_vars script as well thinking that would work, but it doesn't either.
I added this
aoData.push( { "name": "custom_7", "value": "2" } );
What am I doing wrong? I need to be able to control the MySQL query since users will be searching by a form and non-relevant rows should not appear.
Hope this all makes sense.
Thanks in advance for any help you can give.
Michelle
This discussion has been closed.
Replies
You need to do what you are currently doing with the aoData.push (like in this example: http://datatables.net/examples/server_side/custom_vars.html ). However at the moment you have an SQL error:
[code]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY id
asc
LIMIT 0, 10' at line 4
[/code]
Might be worth printing out your generated SQL statement and see where it is going wrong.
Allan
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "name": "grade", "value": "C" } );
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
} );
}
[/code]
It still doesn't work. It shows all 57 when it should only show about 8.
Please see my example here: http://frumtown.com/listings/server_side.html
Allan
note: I'm seeing 2 sets of DOM elements. the top one doesn't work, the bottom one does. are you intiailizing the table more than once?
He wants a pre-filter before the 'live' filtering , so that for example : blahblah.php?custom_7=Gecko only returns gecko browsers, and then the user could filter it a little more by version and so on..
I wanted to do the same but i can't find the solution, have you Studio 6000?