Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

6 posts by 2 authors in: Forums > CMS Builder
Last Post: September 1, 2016

By Daryl - August 30, 2016 - edited: November 22, 2016

Hi Jeremy,

Use array_groupBy() function on your faq_questions records array.
For example:

$faqsTopicsToRecords= array_groupBy($faq_quesitons, 'topics:label', true);

// to see how the new array looks like
showme($faqsTopicsToRecords);

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): ?>
    <p>
      <?php echo $record['question'] ?><br>
      <?php echo $record['answer'] ?><br><br>
    </p>
  <?php endforeach ?>

<?php endforeach ?>

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

Hi Daryl!

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.  :-)

- Jeremy

---------------------------
Dwelling Productions
www.dwellingproductions.com

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!

---------------------------
Dwelling Productions
www.dwellingproductions.com

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.

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

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.

Thanks Daryl!

- Jeremy

---------------------------
Dwelling Productions
www.dwellingproductions.com