• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ExtJS与PHPJson、MYSQL数据读取

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1 建立数据库、注册表

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');

 

2 建立jsonreader.php和get.php

jsonreader.php调用json.js

get.php读取数据库数据

jsonreader.php =>

<html>
<head>
<title>注册</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);
?>

3 extjs文件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:
'简单Grid表格示例',
        applyTo:
'grid',
        width:
250,
        height:
150,
        frame:
true,
        columns:[
            {header:
"id",width:50,dataIndex:'id',sortable:true},
            {header:
"姓名",width:80,dataIndex:'name',sortable:true},
            {header:
"年龄",width:80,dataIndex:'password',sortable:true}
        ]
    })
});


4 运行http://localhost/register/jsonreader.php

 

5 总结

 php获取mysql的数据,转换为数组,然后运用json_encode

    while($row=mysql_fetch_array($result))
    {
        
$arr4[]=$row;
    }
    
echo json_encode($arr4);

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP--------TP中的ajax请求发布时间:2022-07-10
下一篇:
PHPStartup:Unabletoloaddynamiclibrary'/usr/lib64/php/modules/phalcon.so'-/usr/li ...发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap