- Let's start by creating folder data in your ExtJS web project .. wamp\www\ext5-aplikasiku\app\data
- Then create files that will be needed for your json
- Update your koneksi.php to access your dbextjs database in mysql
<?php
$dbhost = "localhost";
$dbname = "dbextjs";
$dbuser = "root";
$dbpwd = "" ; //my MySQL password is empty
$koneksi = mysql_connect($dbhost,$dbuser,$dbpwd) or die("gagal koneksi");
$mydb = mysql_select_db($dbname);
?> - Update your getcategory.php file
<?php
Run the JSON file using your browser (http://localhost/ext5-aplikasiku/data/getcategory.php)
include 'koneksi.php';
//A) paging start and limit handling in ExtJS
if(isset($_GET['start'])) {
$start = $_GET['start'];
} else {
$start = 0;
}
if(isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit= 10;
}
//B) Request data to MySQL and put the data in array
$sql = "select * from tbproductcat order by catid desc Limit $start,$limit";
$query = mysql_query($sql);
$jsonRow = array();
while ($row_data = mysql_fetch_assoc($query)) {
$jsonRow[] = $row_data;
};
//C) Request total row for paging
$total = mysql_query('select count(*) as totalCol from tbproductcat');
$total_data = mysql_fetch_assoc($total);
//D) using json_encode to convert to JSON format
echo json_encode(array
(
"success" => mysql_errno()==0, //callback
"total" => $total_data['totalCol'], //total all data for paging
"category" => $jsonRow // selector as root in store
)
);
?>
the result will look like this
{"success":true,"total":"2","category":[{"catid":"1","catname":"ELEKTRONIK","catstatus":"1"},{"catid":"2","catname":"OTOMOTIF","catstatus":"1"}]}
- Update your getproduct.php script
<?php
include 'koneksi.php';
//A) paging start and limit handling in ExtJS
if(isset($_GET['start'])) {
$start = $_GET['start'];
} else {
$start = 0;
}
if(isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit= 10;
}
//B) Request data to MySQL and put the data in array
$sql = "select * from tbproductsales order by prdid desc Limit $start,$limit";
$query = mysql_query($sql);
$jsonRow = array();
while ($row_data = mysql_fetch_assoc($query)) {
$jsonRow[] = $row_data;
};
//C) Request total row for paging
$total = mysql_query('select count(*) as totalCol from tbproductsales');
$total_data = mysql_fetch_assoc($total);
//D) using json_encode to convert to JSON format
echo json_encode(array
(
"success" => mysql_errno()==0, //callback
"total" => $total_data['totalCol'], //total all data for paging
"product" => $jsonRow // selector as root in store
)
);
?> - Update your getuser.php script
<?php
include 'koneksi.php';
//A) paging start and limit handling in ExtJS
if(isset($_GET['start'])) {
$start = $_GET['start'];
} else {
$start = 0;
}
if(isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit= 10;
}
//B) Request data to MySQL and put the data in array
$sql = "select * from tbusers order by userid desc Limit $start,$limit";
$query = mysql_query($sql);
$jsonRow = array();
while ($row_data = mysql_fetch_assoc($query)) {
$jsonRow[] = $row_data;
};
//C) Request total row for paging
$total = mysql_query('select count(*) as totalCol from tbusers');
$total_data = mysql_fetch_assoc($total);
//D) using json_encode to convert to JSON format
echo json_encode(array
(
"success" => mysql_errno()==0, //callback
"total" => $total_data['totalCol'], //total all data for paging
"appuser" => $jsonRow // selector as root in store
)
);
?>
Copyright
Hery Purnama
http://freelance-it-trainer.blogspot.com
No comments:
Post a Comment