так в чем проблема соббсенно??))
сам sql надо формировать динамически, вот я делал так:
<?php
$start = mysql_real_escape_string($_POST["start"]);
$limit = mysql_real_escape_string($_POST["limit"]);
$sort = mysql_real_escape_string($_POST["sort"]);
$dir = mysql_real_escape_string($_POST["dir"]);
$orders = ($sort == "") ? "" : " order by ".$sort." ".$dir." ";
$limits = ($start == "" && $limit == "") ? "" : " limit ".$start.", ".$limit." ";
$sql = "
select SQL_CALC_FOUND_ROWS
id
, address
FROM
city
".$orders."
".$limits.";";
$query = mysql_query($sql);
$ar = array();
if ($query)
{
while($obj = mysql_fetch_object($query))
{
array_push($ar, array
(
"id" => $obj->id,
"address" => $obj->address
));
}
}
$query = mysql_query("SELECT FOUND_ROWS() as count");
$object = mysql_fetch_object($query);
echo json_encode(array
(
"data" => $ar,
"totalCount" => $object->count
));
?>