The following articles mainly describe the practical application of ExtJS, PHP Json, and MySQL DATA reading, including the establishment of databases, registries, and jsonreader. php and get. php and extjs file json. js writing. The following describes the main content of the article.
ExtJS and PHP Json, MySQL Data Reading 1 Create a database, registry
- create database test;
- create table test.login(
- id int primary key,
- name varchar(20) not null,
- password varchar(20) not null
- );
- insert into test.login values
- ('1','hong','1234'),
- ('2','linxiang','1234'),
- ('3','chen','99a9s'),
- ('4','luxi','aabe2');
ExtJS and PHP Json, MySQL Data Reading 2 build jsonreader. php and get. php
Jsonreader. php calls json. js
Get. php reads database data
- Jsonreader. php =>
- <Html>
- <Head>
- <Title> Registration </title>
- <Link rel = "stylesheet" type = "text/css" href = "../ext/resources/css/ext-all.css"/>
- <Script type = "text/javascript" src = "../ext/adapter/ext/ext-base.js"> </script>
- <Script type = "text/javascript" src = "../ext/ext-all.js"> </script>
- <Script type = "text/javascript" src = "json. js"> </script>
- </Head>
- <Body>
- <Div id = 'grid'> </div>
- </Body>
- </Html>
- Get. php =>
- <? Php
- $ Conn = MySQL_connect ("localhost", "root", "123 ");
- MySQL_select_db ("test ");
- $ SQL = "select id, name, password from login ";
- $ Result = MySQL_query ($ SQL, $ conn );
- While ($ row = MySQL_fetch_array ($ result ))
- {
- $ Arr4 [] = $ row;
- }
- Echo json_encode ($ arr4 );
- ?>
ExtJS, PHP Json, MySQL Data Reading 3 extjs file written in json. js
- json.js=>
- Ext.onReady(function() {
- store=new Ext.data.JsonStore({
- url:'get.php',
- data:[],
- fields:[
- {name:'id'},
- {name:'name'},
- {name:'password'}
- ]
- });
- store.load();
- new Ext.grid.GridPanel({
- store:store,
- mode:'remote',
Title: 'simple Grid table example ',
- ApplyTo: 'grid ',
- Width: 250,
- Height: 150,
- Frame: true,
- Columns :[
- {Header: "id", width: 50, dataIndex: 'id', sortable: true },
- {Header: "name", width: 80, dataIndex: 'name', sortable: true },
- {Header: "Age", width: 80, dataIndex: 'Password', sortable: true}
- ]
- })
- });
4. Run http: // localhost/register/jsonreader. php
5. Summary
Php retrieves MySQL Data, converts it to an array, and then uses json_encode
- while($row= mysql _fetch_array($result))
- {
- $arr4[]=$row;
- }
- echo json_encode($arr4);
The above content is an introduction to Data Reading from ExtJS, PHP Json, and MySQL. I hope you will get some benefits.