Viewing an image from a related table

6 posts by 2 authors in: Forums > CMS Builder
Last Post: February 17, 2015   (RSS)

By northernpenguin - February 15, 2015 - edited: February 15, 2015

I have 2 multi-value tables.  One lists the personnel, while the other lists the positions (2nd field is an image).  How do I display the personnel information for each person plus the position image?

Right now, I'm stumped!

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By claire - February 16, 2015

Hey there - it depends on what the relationship between the two tables is. Can you give me any more information?

--------------------

Claire Ryan
interactivetools.com

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

By northernpenguin - February 16, 2015

Claire:  Right now, one table just lists a set of Air Force ranks and the image (RANKS).  The main table has the personnel information, including name, position, email, rank.  The rank field in this table is a list linked to the RANKS table.  The only field it will let me display is the text rank field, not the uploaded image.

Does that help?

Ragi

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By claire - February 16, 2015

Yes, it does! What you'll have to do is use a second getRecords function to get the RANKS table, and then create a new array of ranks with the num of each rank record as the index to the record. Then if you're outputting the personnel records, you can use the indexed array to get the uploaded photo.

--------------------

Claire Ryan
interactivetools.com

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

By northernpenguin - February 16, 2015 - edited: February 16, 2015

Claire:  I got everything except the "..create a new array of ranks....".  Not sure how to do that.

Ragi

P.S.  Is this what you mean?

<?php
  // load records from 'staff'
  list($staffRecords, $staffMetaData) = getRecords(array(
    'tableName'   => 'staff',
    'loadUploads' => true,
    'allowSearch' => false,
    'debugSql'    => false,      // optional, display SQL query, defaults to no
  ));

  // load records from 'ranks'
  list($ranksRecords, $ranksMetaData) = getRecords(array(
    'tableName'   => 'ranks',
    'loadUploads' => true,
    'allowSearch' => false,
  ));
  
  $rankStructure = getRecords(array(
    'tableName'   => 'ranks',
    'orderBy'   => 'num',
));
?>

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke