extjs load data from mysql with php example
来源:互联网 发布:电脑加速软件 编辑:程序博客网 时间:2024/05/16 01:10
loadData.php:
<?phprequire_once 'lib/response.php';class fruit {var $fruit_id;var $name;var $variety;}$host = "192.168.1.105"; $user = "jet"; $pass = "^^^^^"; $mydb = "fruitdb";$con=mysqli_connect($host,$user,$pass,$mydb);// Check connectionif (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }$result = mysqli_query($con,"SELECT * FROM fruit");$query_array=array();$i=0;//Iterate all Selectwhile($row = mysqli_fetch_array($result)) { //Create New User instance $frt = new fruit(); //Fetch User Info $frt->fruit_id=$row['fruit_id']; $frt->name=$row['name']; $frt->variety=$row['variety']; //Add User to ARRAY $query_array[$i]=$frt; $i++; }//Creating Json Array needed for Extjs Proxy$res = new Response();$res->success = true;$res->message = "Loaded data";$res->data = $query_array;//Printing json ARRAYprint_r($res->to_json());mysqli_close($con);?>
response.php:
<?php/** * @class Response * A simple JSON Response class. */class Response { public $success, $data, $total,$message, $errors, $tid, $trace; public function __construct($params = array()) { $this->success = isset($params["success"]) ? $params["success"] : false; $this->message = isset($params["message"]) ? $params["message"] : ''; $this->data = isset($params["data"]) ? $params["data"] : array(); } public function to_json() { return json_encode(array( 'success' => $this->success, 'message' => $this->message, 'data' => $this->data )); }}
store:
Ext.define('AM.store.Grid', { extend: 'Ext.data.Store', model: 'AM.model.Grid', autoLoad: true, pageSize: 5, // numero de registros por Grid proxy: { type: 'ajax', api: { read: 'data/loadData.php', }, reader: { type: 'json', root: 'data', successProperty: 'success' }, writer: { type: 'json', root: 'data', encode: true } }});
model:
Ext.define('AM.model.Grid', { extend: 'Ext.data.Model', idProperty: 'userID', fields: [{name: 'fruit_id', type: 'int'},'name', 'variety']});
view:
Ext.define('AM.view.Grid' ,{ extend: 'Ext.grid.Panel', alias: 'widget.mygrid', title: 'All Users', initComponent: function() { this.store = 'Grid'; this.columns = [ {header: 'Fruit_id', dataIndex: 'fruit_id', flex: 1}, {header: 'Name', dataIndex: 'name', flex: 1}, {header: 'Variety', dataIndex: 'variety', flex: 1} ]; this.callParent(arguments); }});
- extjs load data from mysql with php example
- Dump data into MySQL from Excel with PHP
- AngularJS CRUD Example with PHP, MySQL and Material Design
- argparse load data from file
- MySQL LOAD DATA Trick
- mysql load data 语法
- mysql load data infile
- mysql:LOAD DATA INFIL
- mysql load data infile
- mysql load data
- mysql load data
- mysql之load data
- mysql load data
- MySQL LOAD DATA命令
- mysql: load data infile
- mysql load data infile
- MySQL Load data
- mysql load data infile
- 我工作这几年(二)
- armeabi和armeabi-v7a
- 强烈推荐口才与幽默全集,看完了,受益匪浅
- Nginx有什么优点?为什么选择Nginx做web服务器软件?
- 程序员怎么写情书
- extjs load data from mysql with php example
- Oracle中HWM浅谈
- Android.mk文件详解介绍
- ant编译带library的工程
- this with
- 递归实现之无限分类
- 史上最烂的代码
- JFreechart生成带热点的饼图
- 动态规划-各种整数划分