Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 25. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  A column for variables to determine output from two tables

phpMyEdit General     A column for variables to determine output from two tables
Odoslať novú tému   Odpovedať na tému    
 
reber     Založený: 23.06.2003   Príspevky: 10  
Príspevok Zaslal: 2004-05-25 23:23
Návrat hore  Odpovedať s citátom     

Hello all,
Can a value1 in table_a serve as a trigger to determine whether value2 is selected from table_a or table_b?

I've recently been successful at joining tables, but here's the challenge:

Two tables.
table_a has numerous columns including addresses. Unfortunately, some of the addresses are incorrect. Table_a is replaced regularly, is managed by somebody else, and is quite large. Making corrections to table_a should be avoided.

Table_b has a few columns with attributes assigned to people listed in the directory table_a. Can one of those attributes be a variable that determines whether the address comes from table_a or a custom address in table_b?

Thanks for any feedback. Maybe there is an easier solution!

cheers/Reber

 
michal     Založený: 17.06.2003   Príspevky: 537   Bydlisko: Slovakia
Príspevok Zaslal: 2004-05-26 10:07
Návrat hore  Odpovedať s citátom     

so if i understand right, you have table:

id, ... , join_table_name, join_table_id

join_table_name - which table to join (in this row)
join_table_id - id in that table

i don't know how sql handels this, and if it can handle it. in a similar problem i've created extra table as a shadow of all possible tables (but that's very ugly).

any ideas from sql gurus ?

 
reber     Založený: 23.06.2003   Príspevky: 10  
Príspevok Zaslal: 2004-05-26 18:54
Návrat hore  Odpovedať s citátom     

Let's say the database has two tables with a key
-----

table_a
column.id
column.key
column.address
column.email

table_b
column.id
column.key
column.customaddress
column.change
-----

I'm was hoping the PME code would support a conditional statement while joining the tables.

Something like, if table_b.change = "yes" then use table_b.customaddress. Else use table_a.address.
----

Possible output for three column PME display:

| a.key | a.email | if b.change=yes then b.customaddress, else a.address |

-----

Does this make sense?
Maybe the value trigger isn't required. Example: if b.customaddress exists use it, else use a.address.

Thanks for your interest in my question, Michal.

cheers/Reber

 
hbernard     Založený: 23.03.2003   Príspevky: 159   Bydlisko: FRANCE
Príspevok Zaslal: 2004-06-11 09:21
Návrat hore  Odpovedať s citátom     

1. Have an hidden virtual field that is doing the custom join :
$opts['fdd']['dummy_field'] = array(
'input' => 'VR',
'options' => '',
'values' => Array(
'table' => 'table_b', //put the joined table here
'column' => 'id',
'description' => 'id', //useless, but required by the implementation
'join' => '$main_table.id = $join_table.id')
);

2. then, use 'sql' field option to display correct value

$opts['fdd']['address'] = array(
'name' => 'custom or initial address',
'sql' => 'if(table_b.address is null, table_a.address, table_b.address)'
);

But this will work only in LVF mode.

Does it fit your need ?

_________________
hbernard - phpMyEdit updater.
 
reber     Založený: 23.06.2003   Príspevky: 10  
Príspevok Zaslal: 2004-08-19 22:18
Návrat hore  Odpovedať s citátom     

Here's how I tackled this.

Kód:
# Ask whether to use substitute address
# Show only during Add, Change, or View
$opts['fdd']['use_address_update'] = array (
  'name' => 'X/A',
  'select'   => 'D',
  'sort'     => true,
  'options'  => 'ACV'
);
$opts['fdd']['use_address_update']['values'] = array('','Yes');
#
#
# Address from uneditable source
# Then check if substutition necessary
$opts['fdd']['placeholder'] = array (
   'name' => 'Address',
   'sql' => 'PMEjoin1.streetAddress',
   'options'  => 'RCPDVL',
   'sort'     => true
);
$opts['fdd']['placeholder']['sql'] = 'IF(TRIM(use_address_update) = "Yes", address_update, PMEjoin1.streetAddress)';
#
#
# Column for substitute address
# Show only during Add, Change, or View
$opts['fdd']['address_update'] = array(
  'name'     => 'Updated Address',
  'select'   => 'T',
  'maxlen'   => 60,
  'sort'     => true,
  'options'  => 'ACV'
);


My follow up questions is this: Can parameters be modified by the data contained within a column?

For example, I'd like to hide the address_update field in Add/Change/View if the record in 'use_address_update' is false.

Cheers,
Reber

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov