I'm working on an Extjs application and I need to get the result of two select queries, encode the results in Json then bind the store containing these results to a gridview.
I have a gridview whith two columns, the first one is "name_scope" and the second is a combobox that should contain the values of the scope (a scope can have multiple values). So I've created two tables in mySQL, "scope" and "scope_value", I want to bind scope_name from "scope" table to my first column, then value(s) from "scope_value" table to the combo column.
I don't think it's a good idea to make two stores for this matter, so I want to make only one php script that would contain these two queries :
SELECT name_scope FROM scope
AND
SELECT value FROM value_scope WHERE name_scope = "'. $name_scope .'"';
These are my tables :
create table scope (name_scope varchar(50) not null primary key, description varchar(100));
create table value_scope (id_value int not null primary key AUTO_INCREMENT,name_scope varchar(50), value varchar(100),
foreign key (name_scope) references scope(name_scope) on delete cascade);
My gridview :
{
xtype: 'container',
id : 'grid_container',
anchor: '100%',
forceFit: true,
items: [{
xtype: 'gridpanel',
id: 'scope_grid',
layout : 'fit',
frame: true,
columnLines: true,
iconCls: 'icon-grid',
title: 'Prod/Rel added',
store: 'GetScopeData',
columns: [{
id: 'n_scope',
text: 'Scope',
flex: 1,
sortable: true,
dataIndex: 'name_scope'},
{ header: 'Product Release',
width: 220,
fixed: true,
hideable: false,
dataIndex: 'value',
editor: {
xtype: 'combobox',
displayField: 'value',
valueField: 'value',
mode: 'local',
editable : false,
typeAhead: false,
triggerAction: 'all',
lazyRender: true,
emptyText: 'Select action',
listClass: 'x-combo-list-small'
}}
]}
What should my php script look like? Please any help would be appreciated.
您可以将这两个选择语句组合成一个,例如
SELECT value FROM value_scope WHERE name_scope in (SELECT name_scope FROM scope);
You can make one store with the result set you want - 2 fields (name_scope and value) and combine your query to one using join:
SELECT scope.name_scope,value FROM scope
INNER JOIN value_scope ON(scope.name_scope = value_scope.name_scope)
WHERE scope.name_scope = "'. $name_scope .'"';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.