*/ // +---------------------------------------------------------------------------- // | Connection settings. Adjust the following lines (see "livegrid.sql"). // +---------------------------------------------------------------------------- $host = 'host'; $user = 'user'; $password = 'passsword'; $database = 'yourdb'; $table = 'yourtable'; // +---------------------------------------------------------------------------- // | Query stuff. As long as everything works fine, you can ignore the following // | lines. Scroll down to the part where the json encoding happens... // +---------------------------------------------------------------------------- $conn = mysql_connect($host, $user, $password); mysql_select_db($database, $conn); $sql2 = "SELECT COUNT(id) AS count_id FROM $table"; $res2 = mysql_query($sql2); $row2 = mysql_fetch_assoc($res2); $length = $row2['count_id']; $feeds = array('response' => array( 'value' => array() )); $sql = "SELECT * FROM $table ORDER BY ".$_POST['sort']." ".$_POST['dir']. " LIMIT ".$_POST['start'].",".$_POST['limit']; $res = mysql_query($sql); while (($row = mysql_fetch_assoc($res))) { $feeds['response']['value']['items'][] = array( 'id' => $row['id'], 'number_field' => $row['number_field'], 'string_field' => $row['string_field'], 'date_field' => $row['date_field'] ); } if (!isset($feeds['response']['value']['items'])) { $feeds['response']['value']['items'] = array(); } $feeds['response']['value']['total_count'] = $length; $feeds['response']['value']['version'] = 1; // +---------------------------------------------------------------------------- // | You need to json_encode the array. If your PHP installation does not support // | json_encode, go and get the Zend Framework at http://framework.zend.com, // | which provides userland json encoding/decoding logic. // +---------------------------------------------------------------------------- if (function_exists('json_encode')) { $json = json_encode($feeds); } else { require_once 'Zend/Json.php'; $json = Zend_Json::encode($feeds); } echo $json; ?>