Need help displaying uploads from a different section

8 posts by 3 authors in: Forums > CMS Builder
Last Post: December 19, 2013   (RSS)

By Codee - December 14, 2013

Hello group - I REALLY need some help on this...spent quite a few hours working on it, then in the forums and realized 'why' I don't know how to do this...

Client sells products and the available colors for those products changes radically and often - therefore I have a table-section for products and a table-section for all colors.  Each color listing in the colors table-section includes an upload named 'graphic'.  Inside the products section I have a field for "available_colors" that is a multi-value pulldown list with 'get options from database (advanced)' from section-tablename 'colors' and field for option values is 'num' and field for option labels is 'title'.  When a product is entered into CMSB and the available colors are chosen (multi-value) obviously from within the 'available_colors' field.  For the LIFE of me I have not been able to get the swatches of the colors (or 'graphic's of those colors from the colors table-section) to appear on the productDetails.php page.  I just realized/remembered that uploads are not stored in the corresponding 'colors' section-table, but instead are stored in the uploads portion of CMSB.

So exactly how do I make the thumbnails of the swatches ('graphic' from the colors section-table) appear on the productDetails.php page so that my client's prospective customers can readily see the available color choices?

And to top it off..this is the one issue delaying finishing this site, and of course, I'm already behind.  Any and all help is TREMENDOUSLY appreciated!!

By gkornbluth - December 15, 2013

Hi,

Didn't we begin this conversation on http://www.interactivetools.com/forum/forum-posts.php?postNum=2232221#post2232221 a while ago?

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Codee - December 15, 2013

Wow! great memory...BUT it's a tad different. 

By ross - December 18, 2013

Hi there

I think I have something for you :).  It gets a little more advanced but I think it's still manageable :).

What I am thinking is creating a function that looks up the images for your colors on the fly as the page lists your products.  Here's an example:

 function getColorUploadSourceByColorNum($colorNumber) {
    
    $imageRecord = mysql_select("uploads", "tableName = 'colors' AND fieldName = 'graphic' AND `order` = '1' AND recordNum = '". mysql_real_escape_string ($colorNumber) ."'");
    
    return $imageRecord[0]['thumbFilePath'];
  }

If you pass this function a number, it will look that up in the uploads table for you and return the thumbnail path to its file.  You might need to adjust

tableName = 'colors' AND fieldName = 'graphic'

but only if I didn't get the names correct.  Next up, calling this function.  In your foreach  loop, you'll need something like this:

<?php foreach($record['color:values'] as $colorNumber): ?>
      <?php if (getColorUploadSourceByColorNum($colorNumber)): ?>
      <img src="<?php echo getColorUploadSourceByColorNum($colorNumber); ?>">      
      <?php endif ?>
      <br/>
<?php endforeach; ?>

It becomes a foreach within a foreach.  Again, you might need to make adjustment to the field names I am using here.  

Does this all make sense? Give it a shot and let me know how you make out. Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Codee - December 18, 2013

Hi Ross!

So, does the function script go in the head of the page.?..specifically the products.php (list page) or productDetails.php (details page)?

and the forEach script to bring in the graphic to the public just goes on the page where I want the graphic to appear, correct?

By ross - December 19, 2013

Hi 

I think you are on the right track here. The function goes at the top of the page (technically it doesn't matter where - that's just where I like to put my functions), and the foreach goes where you want the image to appear.

The code will work for both list and detail pages.  Keep in mind that on the list page, you'll need to put my foreach inside of the main foreach that's cycling through your records.  On both pages, you'll need to make sure where I have $record, you swap it in for what you've called your data set.

Does that all make sense? Keep me up to date with how you are making out. Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By ross - December 19, 2013

Hi

Sounds good! Thanks for the heads up :). Greg just forwarded me your email and I'll be in touch shortly!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/