Sort + Filtering not working somehow

Sort + Filtering not working somehow

janvier1985janvier1985 Posts: 2Questions: 0Answers: 0
edited January 2011 in General
Ok, so iam trying to get DataTables to work with MSSQL (2000/2005)
i get data back from the PHP and seems to work very good

Search: OK
Filtering: NOK
Sorting: NOK
Paging: NOK


here is my script

[code]
<?php
$mssql = array(
'host' => 'XXXXXXXX',
'user' => 'XXXXXXXX',
'pass' => 'XXXXXXXX'
);

$conn = mssql_pconnect($mssql['host'],$mssql['user'],$mssql['pass']);

//Count of all records
$rResultTotal = mssql_query("SELECT COUNT(*) as total_count FROM account.dbo.user_profile",$conn);
$aResultTotal = mssql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];


/* Paging */
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) )
{
$sLimit = "TOP ".( $_GET['iDisplayLength'] );
}

/* Ordering */
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<( $_GET['iSortingCols'] ) ; $i++ )
{
$sOrder .= fnColumnToField(( $_GET['iSortCol_'.$i] ))."
".( $_GET['sSortDir_'.$i] ) .", ";
}
$sOrder = substr_replace( $sOrder, "", -2 );
}


$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE user_no LIKE '%".$_GET['sSearch']."%' OR ".
"user_id LIKE '%".$_GET['sSearch']."%' OR ".
"user_pwd LIKE '%".$_GET['sSearch']."%'

";
}


$fil_Result = mssql_query("SELECT COUNT(*) as filert_info FROM account.dbo.user_profile $sWhere",$conn);
$afil_Result = mssql_fetch_array($fil_Result);
$iFilteredTotal = $afil_Result[0];


$rResult = mssql_query("SELECT $sLimit user_no, user_id, user_pwd From account.dbo.user_profile $sWhere ",$conn);


$sOutput = '{';
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mssql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$sOutput .= '"'.$aRow[0].'",';
$sOutput .= '"'.$aRow[1].'",';
$sOutput .= '"'.$aRow[2].'"';
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';

echo $sOutput;


function fnColumnToField( $i )
{
if ( $i == 0 )
return "user_no";
else if ( $i == 1 )
return "user_id";
else if ( $i == 1 )
return "user_pwd";

}
?>
[/code]

Big thanks in advance

Replies

This discussion has been closed.