Multi-select to display links and images

21 posts by 4 authors in: Forums > CMS Builder
Last Post: June 1, 2009   (RSS)

  • Archived  

By IronVictory - July 3, 2008

I am using the new multi-select drop down list to select products that are related to the main product. I have it set up as:
Get options from Database
Section Tablename: Products
Option Value: model
Option Label: model

On my product detail page, I am using the viewer to display all the model numbers:

<?php echo join(', ', getListLabels('products', 'related_products', $productsRecord['related_products'])); ?>

It displays a list of the Model #'s fine, but I also want to display the thumbnail and a link to the product. How would I do that?

Re: [IronVictory] Multi-select to display links and images

  • Archived  

By Dave - July 4, 2008

Hi IronVictory,

You'll need to store the product numbers as well. Try this:

Section Tablename: Products
Option Value: num
Option Label: model

You'll still be able to use your echo tag abowe to show the names but you'll also be able to get the product numbers with this:

<?php echo join(', ', getListValues('products', 'related_products', $productsRecord['related_products'])); ?>

How do you want the products displayed? Could we use a list viewer and look them up with the product numbers?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multi-select to display links and images

  • Archived  

By IronVictory - July 4, 2008

Yes, I need to display them in a list like this:

<img src>
<a href>[model]</a>

<img src>
<a href>[model]</a>

<img src>
<a href>[model]</a>

They will each link to their product detail page.

Re: [Dave] Multi-select to display links and images

  • Archived  

By IronVictory - July 4, 2008

hmm i'm getting an error on pages where I have selected related products:

========
Notice: Use of undefined constant recordNumbersAsCSV - assumed 'recordNumbersAsCSV' in /home/xxx/domains/xxx.com/public_html/product_detail.php on line 15
========

and an error on pages where i have not selected any related products:

========
Notice: Use of undefined constant recordNumbersAsCSV - assumed 'recordNumbersAsCSV' in /home/xxx/domains/xxx.com/public_html/product_detail.php on line 15 getRecords(products) MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) ORDER BY dragSortOrder, model ASC' at line 2
========

Re: [IronVictory] Multi-select to display links and images

  • Archived  

By Dave - July 4, 2008

Ahh, I had a typo. Try adding the $:

if (!$recordNumbersAsCSV) { $recordNumbersAsCSV = "0"; } // prevent error from having empty string if no matches
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multi-select to display links and images

  • Archived  

By IronVictory - July 4, 2008

That fixed it. So now how do I display each related product's thumbnail, model and link?

Currently only the related product models# are shown using what you gave me earlier:

<?php echo join(', ', getListLabels('products', 'related_products', $productsRecord['related_products'])); ?>

Re: [IronVictory] Multi-select to display links and images

  • Archived  

By Dave - July 7, 2008

Hi IronVictory,

You should be able to loop over $relatedProductRecords, just like if you had created a regular list viewer.

<?php
// get where
$recordNumbersArray = getListValues('products', 'related_products', $productsRecord['related_products']);
$recordNumbersAsCSV = join(', ', $recordNumbersArray);
if (!$recordNumbersAsCSV) { $recordNumbersAsCSV = "0"; } // prevent error from having empty string if no matches

// load all records
list($relatedProductRecords, $relatedProductsMetaData) = getRecords(array(
'tableName' => 'products',
'allowSearch' => '0',
'where' => "num IN ($recordNumbersAsCSV)",
));
?>

<?php foreach ($relatedProductRecords as $record): ?>
Model: <?php echo $record['model'] ?>
...etc...
<?php endforeach ?>


Yuo can probably copy most of the fields from your product list page. If you want to use a different variable just rename $record to whatever you're currently using.

Hope that helps, let me know if that works for you! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Multi-select to display links and images

  • Archived  

By IronVictory - July 7, 2008

That works wonderfully.

Thanks for your help!

Re: [Dave] Multi-select to display links and images

  • Archived  

By Kenny - July 29, 2008

No matter what I change, I still get that MySql error

getRecords(products) MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Window, 3x4 Insulated Window, 4, 8, Extra Set of Doors, Framing Package - $1.75 ' at line 2

I have a section called "products" and it pulls a list from a section called "upgrades" by:

Section Tablename: Upgrades
Option Value: num
Option Label: upgrades


My Top of Page code is:
<?php

require_once "/home/lelands/public_html/webadmin/lib/viewer_functions.php";

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$productsRecord = @$productsRecords[0]; // get first record

// get where
$recordNumbersArray = getListValues('products', 'a_upgrades', $productsRecord['a_upgrades']);
$recordNumbersAsCSV = join(', ', $recordNumbersArray);
if (!$recordNumbersAsCSV) { $recordNumbersAsCSV = "0"; } // prevent error from having empty string if no matches

// load all records
list($relatedProductRecords, $relatedProductsMetaData) = getRecords(array(
'tableName' => 'products',
'allowSearch' => '0',
'where' => "num IN ($recordNumbersAsCSV)",
));

?>



And my content code is:

<?php foreach ($relatedProductRecords as $record): ?>

Upgrades: <?php echo $record['upgrades'] ?>
Price: <?php echo $record['price'] ?>

<?php endforeach ?>



I have tried it many different ways, but this is what it is now.