Sign up |
Use array_groupBy() function on your faq_questions records array.
$faqsTopicsToRecords= array_groupBy($faq_quesitons, 'topics:label', true);
// to see how the new array looks like
Your foreach loop should now look something like this:
<?php foreach ($faqsTopicsToRecords as $topic => $records): ?>
<h1><?php echo htmlencode($topic) ?></h1>
<?php foreach ($records as $record): ?>
<?php echo $record['question'] ?><br>
<?php echo $record['answer'] ?><br><br>
<?php endforeach ?>
<?php endforeach ?>
Hope this helps!
Thanks for your reply! Unfortunately, I'm getting an error with this line:
<?php foreach ($records => $record): ?>
The error I'm receiving is: "syntax error, unexpected T_DOUBLE_ARROW"
I tried several things to fix it, but can't seem to get anywhere. I've uploaded the PHP page I'm working with, in case you want to take a look. Also, I've prepared a scaled back page (faq-simple.php), with all my other code stripped out, for testing purposes. This page is viewable online here: http://dwellingproductions.com/clients/cvrs/faq-simple.php
I've also posted some screenshots of my CMSB pages, to ensure that I'm referencing fields and editor content properly.
I appreciate any help. :-)
Well, I may not need help after all. :-) I decided to change my method of presentation, which I based on this forum post: http://www.interactivetools.com/forum/forum-posts.php?postNum=2230107#post2230107
I'm actually much happier with this approach. I'm not sure why I didn't think of it to begin with. :-)
So, everything is working perfectly now. You can see it here: http://www.dwellingproductions.com/clients/cvrs/faq.php
Thanks IT for this great forum!
It's a typo. I was typing too fast. It should be:
<?php foreach ($records AS $record): ?>
Anyway, I'm glad you got it working.
Actually, thanks so much for following up on that, because I can use the original approach on something else I have coming up. :-) That's going to come in really handy.