Problems With WHERE Clause
Problems With WHERE Clause
![Nachosincolor](https://secure.gravatar.com/avatar/a31624a58f942806e36c2616fd4faaca/?default=https%3A%2F%2Fvanillicon.com%2Fa31624a58f942806e36c2616fd4faaca_200.png&rating=g&size=120)
Hi there everybody... I'm using Datatables to get data from server trough AJAX request and I'm having some serious issues with WHERE clause and hope you can help me:
a) The Ajax request to get the data, is sent with a "GET" variable, this is being used to Filter the JSON response.
b) The server-side php have the WHERE section configured to filter using the GET variable, and the response is filtered
The problem appears when i use the Search filter, and due to it's config:
[code]
$sql_where = "WHERE ID_X=".$_GET['X'];
if ($_GET['sSearch'] != "")
{
$sql_where = "WHERE ";
foreach ($columns as $column)
{
$sql_where .= $column . " LIKE '%" . mysql_real_escape_string( $_GET['sSearch'] ) . "%' OR ";
}
$sql_where = substr($sql_where, 0, -3);
}
[/code]
It filters from the whole SQL's main query, how can i use the Quick Search to filter from the "already filtered" data?
Thanks a lot!
PS = I've tried to put something like
[code]
$sql_where = "WHERE ID_X=".$_GET['X'];
if ($_GET['sSearch'] != "")
{
$sql_where = "WHERE ID_X=".$_GET['X']." AND";
. . .
[/code]
but nothing... Hope this is not a repost, I've search but nothing like this, I know is easy but I just can't see it! Thanks!
a) The Ajax request to get the data, is sent with a "GET" variable, this is being used to Filter the JSON response.
b) The server-side php have the WHERE section configured to filter using the GET variable, and the response is filtered
The problem appears when i use the Search filter, and due to it's config:
[code]
$sql_where = "WHERE ID_X=".$_GET['X'];
if ($_GET['sSearch'] != "")
{
$sql_where = "WHERE ";
foreach ($columns as $column)
{
$sql_where .= $column . " LIKE '%" . mysql_real_escape_string( $_GET['sSearch'] ) . "%' OR ";
}
$sql_where = substr($sql_where, 0, -3);
}
[/code]
It filters from the whole SQL's main query, how can i use the Quick Search to filter from the "already filtered" data?
Thanks a lot!
PS = I've tried to put something like
[code]
$sql_where = "WHERE ID_X=".$_GET['X'];
if ($_GET['sSearch'] != "")
{
$sql_where = "WHERE ID_X=".$_GET['X']." AND";
. . .
[/code]
but nothing... Hope this is not a repost, I've search but nothing like this, I know is easy but I just can't see it! Thanks!
This discussion has been closed.