界面不用多说了吧。喜欢的举手!
这里贴一下数据库访问和ExtJs制作表格的方法
1 访问SQLite 3:
function
get_sqlite3_data()
{
d = new Array();
q = " SELECT * FROM test_table; " ;
db.query(q);
while (db.fetch())
{
idx = db.get_array_data( " idx " );
name = db.get_array_data( " name " );
email = db.get_array_data( " email " );
a = new Array(idx,name,email);
d.push(a);
}
return d;
}
{
d = new Array();
q = " SELECT * FROM test_table; " ;
db.query(q);
while (db.fetch())
{
idx = db.get_array_data( " idx " );
name = db.get_array_data( " name " );
email = db.get_array_data( " email " );
a = new Array(idx,name,email);
d.push(a);
}
return d;
}
2 访问MySQL
2.1 JavaScript部分
function
get_myssql_data(host,user,pwd)
{
create_mysql_data(host,user,pwd);
// php=dvm.GetSharedObject("php");alert(php.get_output_string());
d = new Array();
q = " SELECT * FROM MyMatters; " ;
mysql_db.query(q);
while (mysql_db.fetch())
{
Name = mysql_db.get_array_data( " Name " );
Amount = mysql_db.get_array_data( " Amount " );
Describe = mysql_db.get_array_data( " Description " );
a = new Array(Name,Amount,Describe);
d.push(a);
}
return d;
}
{
create_mysql_data(host,user,pwd);
// php=dvm.GetSharedObject("php");alert(php.get_output_string());
d = new Array();
q = " SELECT * FROM MyMatters; " ;
mysql_db.query(q);
while (mysql_db.fetch())
{
Name = mysql_db.get_array_data( " Name " );
Amount = mysql_db.get_array_data( " Amount " );
Describe = mysql_db.get_array_data( " Description " );
a = new Array(Name,Amount,Describe);
d.push(a);
}
return d;
}
2.2 PHP部分
class
MySQLAccess
{
public $db ;
public $query_result ;
public $row_array ;
public function open( $host , $user , $pwd ){
$this -> db = mysql_connect ( $host , $user , $pwd );
// die($this->db);
mysql_select_db ( " test " );
// $this->query("CREATE TABLE MyMatters(Name varchar(30),Amount int,Kind varchar(16),BuySelf int,Description varchar(255))");
//die(mysql_errno($this->db) . ": " . mysql_error($this->db));
}
public function close(){
mysql_close ( $this -> db);
}
public function query( $sql ){
$this -> query_result = mysql_query ( $sql );
// echo($this->query_result);
}
public function fetch(){
$this -> row_array = mysql_fetch_assoc ( $this -> query_result);
if ( $this -> row_array)
return true ;
return false ;
}
public function get_array_data( $field_name ){
return $this -> row_array[ $field_name ];
}
}
{
public $db ;
public $query_result ;
public $row_array ;
public function open( $host , $user , $pwd ){
$this -> db = mysql_connect ( $host , $user , $pwd );
// die($this->db);
mysql_select_db ( " test " );
// $this->query("CREATE TABLE MyMatters(Name varchar(30),Amount int,Kind varchar(16),BuySelf int,Description varchar(255))");
//die(mysql_errno($this->db) . ": " . mysql_error($this->db));
}
public function close(){
mysql_close ( $this -> db);
}
public function query( $sql ){
$this -> query_result = mysql_query ( $sql );
// echo($this->query_result);
}
public function fetch(){
$this -> row_array = mysql_fetch_assoc ( $this -> query_result);
if ( $this -> row_array)
return true ;
return false ;
}
public function get_array_data( $field_name ){
return $this -> row_array[ $field_name ];
}
}
3 用ExtJs产生表格显示数据
function
show_mysql_data(mysql_data_panel,my_data,host,user,pwd)
{
var xg = Ext.grid;
// shared reader
var reader = new Ext.data.ArrayReader({}, [
{name: ' Idx ' },
{name: ' Name ' },
{name: ' Email ' }
]);
// //////////////////////////////////////////////////////////////////////////////////////
// Grid 1
// //////////////////////////////////////////////////////////////////////////////////////
var grid1 = new xg.GridPanel({
store: new Ext.data.Store({
reader: reader,
data: my_data
}),
cm: new xg.ColumnModel([
{id: ' Idx ' ,header: " 名称 " , width: 3 , sortable: true , dataIndex: ' Idx ' },
{header: " 数量 " , width: 10 , sortable: true , dataIndex: ' Name ' },
{header: " 描述 " , width: 10 , sortable: true , dataIndex: ' Email ' }
]),
viewConfig: {
forceFit: true
},
width: 600 ,
height: 300 ,
collapsible: true ,
animCollapse: false ,
title: ' MySQL 数据 : ' + host + " : " + user + " - " + pwd,
iconCls: ' icon-grid ' ,
renderTo: mysql_data_panel
});
}
{
var xg = Ext.grid;
// shared reader
var reader = new Ext.data.ArrayReader({}, [
{name: ' Idx ' },
{name: ' Name ' },
{name: ' Email ' }
]);
// //////////////////////////////////////////////////////////////////////////////////////
// Grid 1
// //////////////////////////////////////////////////////////////////////////////////////
var grid1 = new xg.GridPanel({
store: new Ext.data.Store({
reader: reader,
data: my_data
}),
cm: new xg.ColumnModel([
{id: ' Idx ' ,header: " 名称 " , width: 3 , sortable: true , dataIndex: ' Idx ' },
{header: " 数量 " , width: 10 , sortable: true , dataIndex: ' Name ' },
{header: " 描述 " , width: 10 , sortable: true , dataIndex: ' Email ' }
]),
viewConfig: {
forceFit: true
},
width: 600 ,
height: 300 ,
collapsible: true ,
animCollapse: false ,
title: ' MySQL 数据 : ' + host + " : " + user + " - " + pwd,
iconCls: ' icon-grid ' ,
renderTo: mysql_data_panel
});
}