我想将数据传递到服务器页面进行搜索,我在服务器文件上回显/打印查询,如果我提供多个参数,它不会连接 where。它只显示最后提供的参数 where。这是我的代码
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push(
{ "name": "type", "value": $('#type_dummy').val() },
{ "name": "category_id", "value": $('#category_id').val() },
{ "name": "region_id", "value": $('#region_id').val() }
);
$.getJSON( sSource, aoData, function (json) {
/* Do whatever additional processing you want on the callback, then tell DataTables */
fnCallback(json)
} );
}
在服务器端处理文件我有这个
$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
if(isset($_GET['type']) && $_GET['type'] != '' ){
$sWhere = "WHERE rent.type = '$_GET[type]' ";
}
if(isset($_GET['category_id']) && $_GET['category_id'] != '' ){
$sWhere = "WHERE rent.category_id = '$_GET[category_id]' ";
}
我直接在 url 中运行这个服务器端文件,并在 url 和打印查询中传递两个参数,它只显示一个参数,就像我的链接一样
/view_match_lead_server.php?type=1&category_id=1
查询的位置是这样的(其他查询没问题)
WHERE category_id=1