Created
August 6, 2011 14:29
-
-
Save anonymous/1129384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//database setting | |
$dbhost='localhost'; | |
$dbuser='root'; | |
$dbpassword=''; | |
$database='db_jqgrid'; | |
$page = $_GET['page']; | |
// get the requested page | |
$limit = $_GET['rows']; | |
// get how many rows we want to have into the grid | |
$sidx = $_GET['sidx']; | |
// get index row - i.e. user click to sort | |
$sord = $_GET['sord']; // get the direction if(!$sidx) | |
$sidx =1; | |
// connect to the database | |
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error()); | |
mysql_select_db($database) or die("Error conecting to db."); | |
$result = mysql_query("SELECT COUNT(*) AS count FROM buku"); | |
$row = mysql_fetch_array($result,MYSQL_ASSOC); | |
$count = $row['count']; | |
if( $count > 0 ) { | |
$total_pages = ceil($count/$limit); | |
} | |
else { | |
$total_pages = 0; | |
} | |
if ($page > $total_pages) $page=$total_pages; | |
$start = $limit*$page - $limit; // do not put $limit*($page - 1) | |
$SQL = "SELECT * FROM book ORDER BY $sidx $sord LIMIT $start , $limit"; | |
$result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error()); | |
$responce->page = $page; | |
$responce->total = $total_pages; | |
$responce->records = $count; | |
$i=0; | |
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { | |
$responce->rows[$i]['id']=$row[id]; | |
$responce->rows[$i]['cell']=array($row[no],$row[title],$row[author],$row[publisher],$row[year_published]); | |
$i++; | |
} | |
echo json_encode($responce); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment