<?php
header('Content-type:text/javascript;charset=UTF-8');
$json=json_decode(stripslashes($_POST["_gt_json"]));
$pageNo = $json->{'pageInfo'}->{'pageNum'};
$pageSize = 10;//10 rows per page

include ("config.php");

 
//mysql_connect("localhost","web19u1","YkmE5Akc") or
//
//    die("Could not connect: " . mysql_error());
//
//mysql_select_db("web19db1") or
//
//    die("Could not select database: " . mysql_error());
   

//to get how many records totally.

$sql = "select count(*) as cnt from student";

$handle = mysql_query($sql);

$row = mysql_fetch_object($handle);

$totalRec = $row->cnt;

 
//make sure pageNo is inbound

if($pageNo<1||$pageNo>ceil(($totalRec/$pageSize))){

  $pageNo = 1;

}

//pageno starts with 1 instead of 0

$sql = 'select * from student  where Gender="Male" limit '.($pageNo - 1)*$pageSize . ', ' . $pageSize;

//$sql = "select * from student  where ".$_GET['field']."='".$_GET['value']."' limit ".($pageNo - 1)*$pageSize . ", " . $pageSize;
//StudentId,Name,AdmissionNo,Gender,StopNumber,TeleNo,Batch,Semester,BusNumber,Status

$handle = mysql_query($sql);    

$retArray = array();

while ($row = mysql_fetch_object($handle)) {

  $retArray[] = $row;

}
$data = json_encode($retArray);

$ret = "{data:" . $data ."}";

/*$ret .= "pageInfo:{totalRowNum:" . $totalRec . "},\n";

$ret .= "recordType : 'object'}";*/

echo $ret;

 

?>
