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)
By gadefgaertgqe - October 7, 2011 - edited: October 7, 2011
Hi,
I have a series of products, and I am showing a list of other products they may be interested in.
To generate the list I am doing the following:
In the product section of CMSB I have added a list of multi-value check boxes to say what other products to suggest. The section is called 'related_models'
The list is generated by using the "Get options from database (advanced)" and simply looks at the current products, so in a way it is looking at itself.
What I can't figure out is how to list the suggested products information. I can show their names but that is it. How would I show for example the images associated with them.
I show their names by doing the following:
Suggestions or pointers will be most welcome :)
Paul
I have a series of products, and I am showing a list of other products they may be interested in.
To generate the list I am doing the following:
In the product section of CMSB I have added a list of multi-value check boxes to say what other products to suggest. The section is called 'related_models'
The list is generated by using the "Get options from database (advanced)" and simply looks at the current products, so in a way it is looking at itself.
What I can't figure out is how to list the suggested products information. I can show their names but that is it. How would I show for example the images associated with them.
I show their names by doing the following:
echo join(', ', getListLabels('peugeot_products_scooters', 'related_models', $peugeot_products_scootersRecord['related_models'])); ?>
Suggestions or pointers will be most welcome :)
Paul
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
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.
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/
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
Worked like a dream. Also took your excellent advice and now use 'num' instead of the name.
Many Thanks
Paul