Listing items from the List Option "Get options from database (advanced)"

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

Re: [Pixels & Beats] Listing items from the List Option "Get options from database (advanced)"

By Jason - October 7, 2011

Hi Paul,

What you would need to do is create a separate query to retrieve those records. The list field is only going to store the value of the options selected (ie, whatever you selected as our option value). From how you're describing the problem, it sounds like you're using the "name" field as your value.

Here is an example of how you can get those records

$relatedModelList = join(',', explode("\t", trim($peugeot_products_scootersRecord['related_models'], "\t")));
$valueFieldName = "name";

if (!$relatedModelList) { $relatedModelList = 0; }


list($relatedModelRecords, $relatedModelMetaData) = getRecords(array(
'tableName' => 'products',
'allowSearch' => false,
'where' => "`$valueFieldName` IN ($relatedModelList)",
));


Change the value of $valueFieldName to whichever field you chose for your list option values. Note that it is usually a good idea to choose "num" as the option value since this will not change if you ever have to change the name of a product.

Hope this helps get you started.
---------------------------------------------------
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: [Jason] Listing items from the List Option "Get options from database (advanced)"

Hi Jason!

Worked like a dream. Also took your excellent advice and now use 'num' instead of the name.

Many Thanks

Paul