Join Tables over a hierarchy

4 posts by 2 authors in: Forums > CMS Builder
Last Post: August 3, 2011   (RSS)

By ryanGT - August 2, 2011 - edited: August 2, 2011

Hi all,

I was just wondering if it possible to join tables in a hierarchy situation.

I have 3 tables linked to each other through 2 different fields.
tableA (level 1)
)
- relatedField1 (dropdown Menu)
)
tableB (level 2)
)
- relatedField2 (dropdown Menu)
)
tableC (level 3)

I need all the results to be returned in one array, so that i can display all the relating data to tableA

Any help would be greatly appreciated.

Many thanks - Ryan

Re: [ryanGT] Join Tables over a hierarchy

By Jason - August 2, 2011

Hi Ryan,

Are you currently able to get all of the information you need as 3 different arrays (ie, 3 different database calls)?

If so, the easiest solution would be to use array_merge() to combine them all into 1 array like this:

<?php
$mergedArray = array_merge($tableARecords, $tableBRecords, $tableCRecords);
?>


Does this sound like what you're looking for?

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [ryanGT] Join Tables over a hierarchy

By Jason - August 3, 2011

Hi Ryan,

Are all three queries just returning a single record? If so, and if you need to output information from each table individually, you'd probably be better off just referencing the records one at a time. For example:

Table A Title: <?php echo $tableA['title'];?>
Table B Tile: <?php echo $tableB['title'];?>


Would this work for you? If not, could you please attach the .php file you are currently working with and I'll see if I can make any suggestions.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/