| Index
» Projekty
» phpMyEdit
» Fórum
» Adding multiple fields from other table to view |
 |
stefanl
Založený: 06.02.2004
Príspevky: 5
Zaslal: 2004-02-06 15:54
Návrat hore
Odpovedať s citátom
|
Tried to read up on this, but can't find out how from the docs.
I have two tables:
A:
id
field1
field2
B:
id
field3
field4
Now I want the display view to look like this:
| id | field1 | field2 | field3 | field4 |
showing all rows with id present in A, displaying field3, field4 whereever there's a corresponding row in B and nothing otherwise. Field3 and field4 should appear as columns on their own, with the ability to sort, search, etc.
I've managed to substitute values from field1, replacing them with values from B.field4 when they are present and keeping field1 original values when there is no matching row in table B.
[Edit:]
Example application:
members:
membership_id
name
zip
geo:
zip
city
View would be
m.membership_id m.name m.zip g.city
Seems too trivial for me to trip and fall on it, but I can't figure out from docs how to do this.
|
stefanl
Založený: 06.02.2004
Príspevky: 5
Zaslal: 2004-02-08 23:16
Návrat hore
Odpovedať s citátom
|
This would be one way to do it. It works to display the fields and for sorting. But it doesn't work for queries (uses master table's primary keys instead of target value in joined table). Perhaps I'm missing the use of some option, so in that case please I'd be grateful if somebody pointed it out to me.
$opts['fdd']['blank1'] = array(
'name' => 'Line items',
'maxlen' => 40,
'required' => true,
'sort' => true,
'values' => array(
'table' => 'opportunities',
'column' => 'siebel_id',
'description' => 'line_items'),
'sql' => 'IF(line_items IN ("Y","N","U"),line_items,"")'
);
$opts['fdd']['join_pdq_generated'] = array(
'name' => 'PDQ generated',
'maxlen' => 40,
'required' => true,
'sort' => true,
'values' => array(
'table' => 'opportunities',
'column' => 'siebel_id',
'description' => 'pdq_generated'),
'sql' => 'IF(pdq_generated IN ("Y","N","U"),pdq_generated,"")'
);
|
hbernard
Založený: 23.03.2003
Príspevky: 159
Bydlisko: FRANCE
Zaslal: 2004-02-09 19:07
Návrat hore
Odpovedať s citátom
|
(Please note that I'm not sure to understand the link beetween your two posts :-()
1/ If you don't want to be able to sort on each column, you can just concatenate zip and city field with an 'sql' option].
2/ But I understand you want to have the 'city' in a separate column.
The trouble is that there is just one join column in the main table.
Then, you have to restrict the field in LFV mode
(else you will get errors in ACPD modes because the field doesn't existin the main table).
So :
- use this for displaying the 'zip' code :
$opts['fdd']['zipfoo'] = Array(
'name' => 'Zip Code',
'sql' => 'PMEtable0.zip'
'options|LFV' => 'LFV', // process it only in LFV mode.
'options|ACPD' => ''
)
- display the city name by using usual join :
$opts['fdd']['zip'] = Array(
'name' => 'City',
'values' => Array(
'table' => 'geo',
'column' => 'zip',
'description' => 'city')
)
(With this sample, users have a dropdown in ADD/EDIT mode to choose zip/city value)
You can't have both in ADD/EDIT forms because you will have two different values for the same field.
If you want to display Zip code in ACPD mode, use conditionnal fields options and multiple fields dropdown according to the documentation
3/ This will be easier when 'virtual' fields will be available.
I hope I didn't misunderstand your question.
-Hugues
|
|
Odoslať novú tému
Odpovedať na tému
|
|
|
|