Multi-select to display links and images
21 posts by 4 authors in: Forums > CMS Builder
Last Post: June 1, 2009 (RSS)
By IronVictory - July 3, 2008
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
By Dave - July 4, 2008
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?
interactivetools.com
Re: [Dave] Multi-select to display links and images
By IronVictory - July 4, 2008
<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: [IronVictory] Multi-select to display links and images
By Dave - July 4, 2008 - edited: July 4, 2008
// 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)",
));
Note, you'll want to go and re-save any of your old related product fields. If they still have the product name instead of the product number you'll get an error.
Hope that helps!
interactivetools.com
Re: [Dave] Multi-select to display links and images
By IronVictory - July 4, 2008
========
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
By Dave - July 4, 2008
if (!$recordNumbersAsCSV) { $recordNumbersAsCSV = "0"; } // prevent error from having empty string if no matches
interactivetools.com
Re: [Dave] Multi-select to display links and images
By IronVictory - July 4, 2008
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
By Dave - July 7, 2008
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! :)
interactivetools.com
Re: [Dave] Multi-select to display links and images
By IronVictory - July 7, 2008
Thanks for your help!
Re: [Dave] Multi-select to display links and images
By Kenny - July 29, 2008
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.