Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Sobota, 28. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Advanced table lookup -- joining three tables

phpMyEdit Features     Advanced table lookup -- joining three tables
Odoslať novú tému   Odpovedať na tému   Choď na stránku Predchádzajúci  1, 2, 3  
 
sagiben     Založený: 27.01.2009   Príspevky: 15  
Príspevok Zaslal: 2009-01-30 11:05
Návrat hore  Odpovedať s citátom     

sagiben Napísal:
Hi all,

Does anyone know if there is a similar patch for
phpMyEdit-mce-cal.class.php ?
I need to use the "multi join" option and a calender
in the same form.

Thank you.


I found that no patch for phpMyEdit-mce-cal.class.php is needed

Thanks

 
paddywwoof     Založený: 25.02.2010   Príspevky: 7  
Príspevok Zaslal: 2010-02-25 18:32
Návrat hore  Odpovedať s citátom     

In order to get this working with a combination of fields from the linked table as well as the linked-linked table I had to further modify the code to use unique aliases for the different tables
Kód:

...
/**/            $tbl_count = 0;
            foreach ($desc['columns'] as $key => $val) {
               if ($val) {
                  $tbl_count++;
//                  $qparts['select'] .= 'IFNULL(CAST('.$this->sd.$val.$this->ed.' AS CHAR),"")';

/**/                  //$qparts['select'] .= 'IFNULL(CAST('.$this->sd.$val.$this->ed.' AS CHAR),"")';
/**/                  if ($desc['values'][$key]) {
/**/                     $qparts['select'] .= 'IFNULL(CAST(PGtbl'.$field_num.'_'.$tbl_count.'.'.$desc['values'][$key]['description'].' AS CHAR),"")';
/**/                     $qparts['from'] .= ", ".$dbp.$desc['values'][$key]['table']." AS PGtbl".$field_num."_".$tbl_count;
/**/                     if ($qparts['where'] != '') $qparts['where'] .= ' AND ';
/**/                     $qparts['where'] .= "$table.".$this->sd.$val.$this->ed." = PGtbl".$field_num."_".$tbl_count.".".$desc['values'][$key]['column'];
...


I have to use the linked table as the name for the second link in a rather ugly and unnecessary join. i.e. dividends.holdingID -> sh_holding.ID, sh_holding.StockID -> sh_stock.ID I have to link sh_holding to sh_holding in order to display the two fields (purchasedate and quantity) along with the description from sh_stock.name (!!) like:
Kód:

$opts['fdd']['holdingID'] = array(
  'name'     => 'HoldingID',
  'select'   => 'T',
  'values'   => array(
    'table'  => 'sh_holding',
   'column' => 'ID',
   'description' => array(
     'columns' => array('ID', 'ID', 'StockID'),
     'divs' => array(' [', '] ',''),
     'values' => array(
       array(
        'table' => 'sh_holding',
          'column' => 'ID',
         'description' => 'Purchdate'
      ),      
       array(
        'table' => 'sh_holding',
          'column' => 'ID',
         'description' => 'quantity'
      ),      
       array(
        'table' => 'sh_stock',
          'column' => 'ID',
         'description' => 'name'
      )
     )
   )
  ),


 
sagiben     Založený: 27.01.2009   Príspevky: 15  
Príspevok Zaslal: 2010-08-18 09:36
Návrat hore  Odpovedať s citátom     

I think the best way to make phpMyEdit read/update date from more then 2 tables is just create a view in mysql with all the data one need and refer to this new table from phpMyEdit.

A view is a virtual table that is defined in advance but it gets the data in runtime.

One can create a view which contains a join of 3 tables and more and use it like it is a regular table.

Sagi.

 
nikolay133     Založený: 07.08.2014   Príspevky: 1  
Príspevok Zaslal: 2014-08-07 09:57
Návrat hore  Odpovedať s citátom     

The simplest solution that I have found is not to use this wonderful patch at all, not to use phpMyEdit joins at all, and use SQL subquery in SELECT, with a dummy phpMyEdit field:

To show one-to-many values via 'device_to_recipes':
Kód:

// Turn on $debug_query, and replace 'PMEtable0'.`id` with the renamed table name and column that you want from the SQL shown.
$opts['fdd']['dummy'] = array (
   'name' => 'Recipes',
   'sql' => "(SELECT GROUP_CONCAT(`name` SEPARATOR ', ') FROM  `recipe` AS r JOIN `device_to_recipes` AS dr ON (r.`id` = dr.`recipe_id`) WHERE dr.`device_id` = PMEtable0.`id`)",
   'options'  => 'RACPDVL',
   'escape' => false,
//   'URL' => 'mailto:',
   'sort'     => true
);


To show one-to-many values with ckickable links to edit this mapping:
Kód:

// Turn on $debug_query, and replace 'PMEtable0'.`id` with the renamed table name and column that you want from the SQL shown.

// Link to edit the mapping.
$href_link = 'device_to_recipes.php?device_id=';

$opts['fdd']['dummy'] = array (
   'name' => 'Recipes',
   'sql' => "(SELECT GROUP_CONCAT(CONCAT('<a href=\"" . $href_link . "', `r`.`id` , '\">', '[', `r`.`id`, ']' ,`r`.`name`, '</a>') SEPARATOR ', ') FROM  `recipe` AS r JOIN `device_to_recipes` AS dr ON (r.`id` = dr.`recipe_id`) WHERE dr.`device_id` = PMEtable0.`id`)",
   'options'  => 'RACPDVL',
   'escape' => false,
//   'URL' => 'mailto:',
   'sort'     => true
);


And implement the $opts['filters'] in the link target (e.g. "device_to_recipes.php?device_id=").


Otherwise , you can do simple SQL subquery select and implement the link in a php file:
Kód:

$opts['fdd']['device_link'] = array(
    'name' => 'Device',
    'options' => 'VLF', // show only in view, list and filter.
    'sql' => "(SELECT CONCAT('[', `id`, ']' , `name`) FROM  `device` AS d WHERE d.`id` = PMEtable0.`device_id` ORDER BY d.`id` LIMIT 1 )",
    'php' => 'desc_to_device_link.php',
    'select' => 'T',
    'sort' => true
);



'desc_to_device_link.php' file that generates an http link from the SQL result above:
Kód:

<?php
preg_match_all('/^\[\d+\].*/', $value, $matches);
if ($matches){
    $id = preg_replace('/\[(\d+)\].*/', "\\1", $value, 1);
    echo "<a href=device.php?id=" . $id . "'>" . $value . "</a>";
    } else {
        echo $value;
    }
?>


NOTICE:
SQL dummy fields are not editable. However for three level joins, you can define standard phpMyEdit join fields and enable on editable pages with the following options:
Kód:

'options' => 'ACPD'


And enable the unediable SQL field on View, LIST and FILTER pages with the following options:
Kód:

'options' => 'VLF'


 
Odoslať novú tému   Odpovedať na tému   Choď na stránku Predchádzajúci  1, 2, 3  

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