Big Question

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 31, 2010   (RSS)

Re: [Dan Maitland] Big Question

By Jason - March 30, 2010

Hi Dan,

One way to do this is to add a field in the "wine" section called producer. Make it a list field. Under list options, select "Get options for database". Select you "producers" table, select "num" for the values, and "title" for the labels.

Now when you go to add a wine to the wine section, there will be a dropdown with all producers.

Finally, in your Producer list or display page, you can use the following code to display all the wines they are associated with:

<?php
list($wineRecords,$wineMetaData)= getRecords(array(
'tableName' => 'wine',
'where' => 'producer='.$record['num']
))
?>
<?php foreach($wineRecords as $wine): ?>
<?php echo $wine['title'] ?>,<?php echo $wine['year'] ?><br />
<?php endforeach ?>


You'll have to adjust the names based on how you've named things. But this will list the wines associated with a given producer.

Let me know if that helps.
---------------------------------------------------
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] Big Question

Jason,
Are you sure there isn't supposed to be an if statement in there somewhere? From the looks of the code I think that will just call all wines and not just the ones associated through the list. I could definitely be wrong but it just doesn't look right for some reason.

Re: [Dan Maitland] Big Question

By Jason - March 31, 2010

Hi Dan,

This code should work. You would put it right where you want the wines of a producer listed. The line: " 'where' => 'producer='.$record['num'] " means that it will only take wine records from the database that have a producer field that is the same as the current producer that is being printed out.

Give it a try and let me know if there are any problems.
---------------------------------------------------
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] Big Question

KILLER!! I'll try it out and let you know. Thanks J.