foreach variations

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 3, 2008   (RSS)

Re: [rez] foreach variations

By rez - December 2, 2008 - edited: December 2, 2008


[font "Arial"]list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'collection_title = "Events"',

));

list($news2Records, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => 'collection_title = "Daily Specials"',

));

?>






Got it. You can put multiple lists on one page. so the "$news2Records" is a variable. Whats the "$newsMetaData" part for?

Also, how would i let the client create the "collection title"s? Currently, i am making the collections (categories) myself and using radio buttons. So I have to make a new list and <collection title =""> tag for each one. As you can see, the collection tag happens once for each group of items. Inside that tag, multiple items are listed. So this would have to be some nested loop situation? Any examples?

Re: [rez] foreach variations

By Dave - December 3, 2008

Hi rez,

I'm not sure what your content is, but one way to do it would be to let your clients enter the collection_title. Either by having it be a text field or making it a list field that loads from another section "Collection Titles" that only has fields for num and name.

Once that is working, you can have your viewer sort by collection_title like this:

'orderBy' => 'collection_title',

And then only show the first instance of each section_title with the code in this post:
http://www.interactivetools.com/forum/gforum.cgi?post=64795#64795

Then all the records in that section after. Hope that makes sense. Let me know if you have more questions about that.

The $newsMetaData contains extra information about the list of records that was returned such as page number, etc. You can see what it contains (or any other PHP variable for that matter) with this code:

<xmp><?php print_r($newsMetaData) ?></xmp>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com