Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Tuesday, November 24, 2026
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  phpMyEdit  »  Forum  »  Advanced table lookup -- joining three tables

phpMyEdit Features     Advanced table lookup -- joining three tables
Post new topic   Reply to topic   Goto page Previous  1, 2, 3  
 
sagiben     Joined: 27 Jan 2009   Posts: 15  
Post Posted: 2009-01-30 11:05
Back to top  Reply with quote     

sagiben wrote:
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     Joined: 25 Feb 2010   Posts: 7  
Post Posted: 2010-02-25 18:32
Back to top  Reply with quote     

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
Code:

...
/**/            $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:
Code:

$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     Joined: 27 Jan 2009   Posts: 15  
Post Posted: 2010-08-18 09:36
Back to top  Reply with quote     

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     Joined: 07 Aug 2014   Posts: 1  
Post Posted: 2014-08-07 09:57
Back to top  Reply with quote     

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':
Code:

// 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:
Code:

// 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:
Code:

$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:
Code:

<?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:
Code:

'options' => 'ACPD'


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

'options' => 'VLF'


 
Post new topic   Reply to topic   Goto page Previous  1, 2, 3  

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Application form
Report bug on PLATON.SK website · Terms of use · Privacy policy