MySQL Data Reading, ExtJS and PHP Json

Source: Internet
Author: User
Tags php json

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

 
 
  1. create database test;  
  2. create table test.login(  
  3. id int primary key,  
  4. name varchar(20) not null,  
  5. password varchar(20) not null  
  6. );  
  7. insert into test.login values  
  8. ('1','hong','1234'),  
  9. ('2','linxiang','1234'),  
  10. ('3','chen','99a9s'),  
  11. ('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

 
 
  1. Jsonreader. php =>
  2. <Html>
  3. <Head>
  4. <Title> Registration </title>
  5. <Link rel = "stylesheet" type = "text/css" href = "../ext/resources/css/ext-all.css"/>
  6. <Script type = "text/javascript" src = "../ext/adapter/ext/ext-base.js"> </script>
  7. <Script type = "text/javascript" src = "../ext/ext-all.js"> </script>
  8. <Script type = "text/javascript" src = "json. js"> </script>
  9. </Head>
  10. <Body>
  11. <Div id = 'grid'> </div>
  12. </Body>
  13. </Html>
  14. Get. php =>
  15. <? Php
  16. $ Conn = MySQL_connect ("localhost", "root", "123 ");
  17. MySQL_select_db ("test ");
  18. $ SQL = "select id, name, password from login ";
  19. $ Result = MySQL_query ($ SQL, $ conn );
  20. While ($ row = MySQL_fetch_array ($ result ))
  21. {
  22. $ Arr4 [] = $ row;
  23. }
  24. Echo json_encode ($ arr4 );
  25. ?>

ExtJS, PHP Json, MySQL Data Reading 3 extjs file written in json. js

 
 
  1. json.js=> 
  2. Ext.onReady(function() {  
  3. store=new Ext.data.JsonStore({  
  4. url:'get.php',  
  5. data:[],  
  6. fields:[  
  7. {name:'id'},  
  8. {name:'name'},  
  9. {name:'password'}  
  10. ]  
  11. });  
  12. store.load();  
  13. new Ext.grid.GridPanel({  
  14. store:store,  
  15. mode:'remote',  

Title: 'simple Grid table example ',

 
 
  1. ApplyTo: 'grid ',
  2. Width: 250,
  3. Height: 150,
  4. Frame: true,
  5. Columns :[
  6. {Header: "id", width: 50, dataIndex: 'id', sortable: true },
  7. {Header: "name", width: 80, dataIndex: 'name', sortable: true },
  8. {Header: "Age", width: 80, dataIndex: 'Password', sortable: true}
  9. ]
  10. })
  11. });

4. Run http: // localhost/register/jsonreader. php

5. Summary

Php retrieves MySQL Data, converts it to an array, and then uses json_encode

 
 
  1. while($row= mysql _fetch_array($result))  
  2. {  
  3. $arr4[]=$row;  
  4. }  
  5. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.