PHP (PDO) naar Ext JS Grid
Wat ik ook probeer , ik krijg alleen een aantal lege rijen in mijn grid .. de data zelf laat hij niet zien.
Mijn Php code:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$dsn = 'mysql:dbname=test;host=localhost';
$user = 'root';
$password = '';
$dbh = new PDO($dsn, $user, $password);
$stmt = $dbh->prepare('SELECT firstname FROM presidents');
$stmt->execute();
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$firstname[] = $row['firstname'];
}
echo json_encode ($firstname);
?>
$dsn = 'mysql:dbname=test;host=localhost';
$user = 'root';
$password = '';
$dbh = new PDO($dsn, $user, $password);
$stmt = $dbh->prepare('SELECT firstname FROM presidents');
$stmt->execute();
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
$firstname[] = $row['firstname'];
}
echo json_encode ($firstname);
?>
Ext Js grid:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?
Ext.onReady(function(){
var grid = new Ext.grid.GridPanel
({
title: 'Basic Grid Panel with Ext JS and PHP',
renderTo: document.body,
width: 600,
height: 300,
frame: true,
autoExpandColumn: 'message',
style: 'margin: 30px auto',
store: new Ext.data.JsonStore({
// store configs
autoLoad: true,
url: 'grid.php',
// reader configs
//root: 'feedback',
fields: [{firstname: 'firstname', mapping: 'first_name'}, 'email', 'subject', 'message']
}),
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: false
},
columns: [
{header: 'firstname', dataIndex: 'firstname'},
{header: 'Email', dataIndex: 'email'},
{header: 'Subject', dataIndex: 'subject'},
{header: 'Message', dataIndex: 'message', id: 'message'}
]
})
})
});
?>
Ext.onReady(function(){
var grid = new Ext.grid.GridPanel
({
title: 'Basic Grid Panel with Ext JS and PHP',
renderTo: document.body,
width: 600,
height: 300,
frame: true,
autoExpandColumn: 'message',
style: 'margin: 30px auto',
store: new Ext.data.JsonStore({
// store configs
autoLoad: true,
url: 'grid.php',
// reader configs
//root: 'feedback',
fields: [{firstname: 'firstname', mapping: 'first_name'}, 'email', 'subject', 'message']
}),
colModel: new Ext.grid.ColumnModel({
defaults: {
width: 120,
sortable: false
},
columns: [
{header: 'firstname', dataIndex: 'firstname'},
{header: 'Email', dataIndex: 'email'},
{header: 'Subject', dataIndex: 'subject'},
{header: 'Message', dataIndex: 'message', id: 'message'}
]
})
})
});
?>
------------
Wat ik heb geprobeerd:
Eerst heb ik geprobeerd om alle rijen data mee te geven (maar dat maakte niks uit)
Toen heb ik geprobeerd of het aan de naamgeving lag .. maar die lijkt wel goed te zijn.
---
De data na json encode ziet er zo uit:
["George","John","Thomas","James","James","John","Andrew","Martin","William","John
","James","Zachary","Millard","Franklin","James","Abraham","Andrew","Ulysses","
Rutherford","James","Chester","Grover","Benjamin","Grover","William","Theodore",
"William","Woodrow","Warren","Calvin","Herbert","Franklin","Harry","Dwight","John"
,"Lyndon","Richard","Gerald","Jimmy","Ronald","George H.","Bill"]
Voor de json encode (print_r) ziet het er zo uit:
Array ( [0] => George [1] => John [2] => Thomas [3] => James [4] => James [5] => John [6] => Andrew [7] => Martin [8] => William [9] => John [10] => James [11] => Zachary [12] => Millard [13] => Franklin [14] => James [15] => Abraham [16] => Andrew [17] => Ulysses [18] => Rutherford [19] => James [20] => Chester [21] => Grover [22] => Benjamin [23] => Grover [24] => William [25] => Theodore [26] => William [27] => Woodrow [28] => Warren [29] => Calvin [30] => Herbert [31] => Franklin [32] => Harry [33] => Dwight [34] => John [35] => Lyndon [36] => Richard [37] => Gerald [38] => Jimmy [39] => Ronald [40] => George H. [41] => Bill )
Dit is de eerst keer dat ik met Ext Js werk , ik wil dit ook werkend krijgen om wat te kunnen experimenteren ermee. (leren)
Bij voorbaat dank!
Toevoeging op 28/09/2010 18:06:48:
Heeft iemand hier ooit zijn beeldscherm het raam uit willen gooien? -> ik ben bijna op dat punt.. HAHA
Gewijzigd op 28/09/2010 11:19:56 door Don Gargonzola
Er zijn nog geen reacties op dit bericht.