Category issue

6 posts by 3 authors in: Forums > CMS Builder
Last Post: February 2, 2010   (RSS)

Re: [Dan Maitland] Category issue

By flamerz - January 30, 2010 - edited: January 30, 2010

I think you can do a wines table (category type), and insert a pulldown multivalue field in your multicategory table of wine distributors to set eachwine that producer has.

in the multicategory set "get options from database", database "wines", option values: num and option labels: name.

You have a nice tutorial about categories in this forum.

wine producers
title textfield
Content wysiwyg
Wines (ctrl+clic) list *

wines
title textfield
Content wysiwyg

* this one set as multicategory

Re: [Dan Maitland] Category issue

Ok so I am able to set it up so that I can have a list menu in appear when creating a new wine record and it will let me choose any producer that I have already entered. Great.

But what I don't get is how do I now create a details page for a producer and have it also show only the wines that are associated to that particular producer. I know it must be possible but I just don't see it. Please if anyone can give me a more detailed explanation it would be greatly appreciated.

Re: [Dan Maitland] Category issue

Please, can someone help me to get this working. The site I'm building depends on this small but important function.

Re: [Dan Maitland] Category issue

By flamerz - February 1, 2010

Hi again.

in your details page you will have the wine producer and his wines.

you can generate the wines list from the cms.

but, to show each wine and its details, you have to load this way:

$winearray = getListValues('producers', 'wine', $producersRecord['wine']);
$wineascsv = join(', ', $winearray);

list($winesRecords, $winesMetaData) = getRecords(array(
'tableName' => 'wines',
'where' => "num in (0, $wineascsv)",
));

first is get the tab separated field and convert to comma separated values, and second is assemble the query.

after this you can echo it:

<?php foreach ($winesRecords as $record): ?>
Name: <?php echo $record['name'] ?><br/>
Content: <?php echo $record['content'] ?><br/>

<?php endforeach ?>


i hope you can get the way to do, sorry if i did some bug in the code. (i hope not, but im traveling and just writing from my small laptop in hotel). [pirate]

Re: [Dan Maitland] Category issue

By Chris - February 2, 2010

Hi Dan,

But what I don't get is how do I now create a details page for a producer and have it also show only the wines that are associated to that particular producer.


Are wines associated with one producer or can they be associated with more than one producer?

I'm going to assume that each wine is made by one producer. Please let me know if this is not the case and I'll show you how to solve that problem.

You can use a "where" clause to load only the Wine records which have their producer field set to the producer you're showing:

list($producersRecords, ) = getRecords(array(
'tableName' => 'producers',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$producerRecord = $producerRecords[0];
list($wineRecords, ) = getRecords(array(
'tableName' => 'wine',
'where' => 'producer = "' . mysql_escape($producerRecord['num']) . '"',
));


If you aren't sure how to to integrate this code, please post the full PHP source code of your producer detail page and I'll show you what to change.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris