Hello i'm trying to populate a combobox with data coming from MYSQL database. Using Extjs 4 with the MVC architecture.
Here's the combobox configuration within my view :
...
{
xtype: 'combobox',
id: 'cmbMetric',
name: 'metr',
mode: 'queryMode',
querymode : 'lcoal',
fieldLabel: 'Metric',
store: 'MetricsData',
editable: false,
valign : 'middle',
margin : 15
}
....
My store :
Ext.define('Metrics.store.MetricsData', {
extend: 'Ext.data.Store',
model: 'Metrics.model.MetricsData',
autoLoad: true,
proxy : {
type : 'ajax',
actionMethods : 'POST',
api : {
read : 'testmysql.php'
},
reader: {
type: 'json',
successProperty: 'success',
messageProperty: 'message',
root: 'data'
}
}
});
My model :
Ext.define('Metrics.model.MetricsData', {
extend: 'Ext.data.Model',
fields: [{name : 'name_metric'}]
});
Finally my PHP script :
<?php
//database parameters
$user='user';
$pw='';
$db='mydb';
$table='metric';
//make database connection
$connection = mysql_connect("localhost", $user, $pw) or
die("Could not connect: " . mysql_error());
mysql_select_db($db) or die("Could not select database");
metricsName();
function metricsName()
{
$sql = 'SELECT name_metric FROM metric';
$result = mysql_query($sql); // result set
while($rec = mysql_fetch_array($result, MYSQL_ASSOC)){
$arr[] = $rec;
};
$data = json_encode($arr); //encode the data in json format
}
?>
I don't know what's wrong or where the error is coming from, but my combobox is never filled. Any help would be much appreciated.