Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 13.59.217.1
<?php
// initialization
$dbhost = 'logisys5';
$dbuser = 'root';
$dbpassword = '';
$database = 'ihms';
$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;
}
$totalrows = isset($_GET['totalrows']) ? $_GET['totalrows']: false;
if($totalrows) {
$limit = $totalrows;
}
// connect to the database
$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Database connection error.");
// get the count of rows
$result = mysql_query("SELECT COUNT(*) AS count FROM masitem");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$count = $row['count'];
// get the required variables
if( $count >0 ) {
$total_pages = ceil($count / $limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) {
$page = $total_pages;
}
if ($limit < 0) {
$limit = 0;
}
$start = $limit * $page - $limit;
if ($start < 0) {
$start = 0;
}
// get the actual stuff to be displayed in the grid
$SQL = "SELECT fitemcode as id, fitemname as name, fbinno as code FROM masitem ORDER BY fitemname, $sidx $sord LIMIT $start , $limit";
$result = mysql_query($SQL) or die("Could not execute query." . mysql_error());
// create a response array from the obtained result
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$response->rows[$i]['id'] = $row['id'];
$response->rows[$i]['cell'] = array($row['id'],$row['name'],$row['code']);
$i++;
}
// convert the response into JSON representation
echo json_encode($response);
// close the database connection
mysql_close($db);
?>
|