multi select display / checkboxes

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

By rez - February 4, 2020 - edited: February 4, 2020

I have a detail page casestudies.php?1  that shows a client. In the client editor / table is a multi list of checkboxes for services performed for that client coming from a services editor / table.

  list($clientRecords, $clientMetaData) = getRecords(array(
    'tableName'   => 'client',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));

  list($servicesRecords, $servicesMetaData) = getRecords(array(
    'tableName'   => 'services',		
    'loadUploads' => true,
    'allowSearch' => false,
  ));

so on casestudies.php?1 I can show all of the checked services (from the code generator):

Services (labels): <?php echo join(', ', $clientRecord['services:labels']); ?><br>

That lists them all in one place separated by commas. How do I loop through this so I can show them in a <UL> for more control of the display?

By daniel - February 4, 2020

Hi rez,

I think something like this should work:

<ul>
<?php foreach ($clientRecord['services:labels'] as $label): ?>
  <li><?php echo $label; ?></li>
<?php endforeach; ?>
</ul>

Let me know if that does the trick or if you have any other questions.

Thanks!

Daniel
Technical Lead
interactivetools.com

By rez - February 5, 2020 - edited: February 5, 2020

Oh. I used categories and the snippets i have from a long time ago are more complicated. Just getting back into CMSB again. 

So all my pages with categories were lists like:

'where' => "category LIKE '%\t{$selectedCategory['num']}\t%'",

That type of thing, looping out results, and some array tricks I have saved has always given me pretty much everything I needed for things like a restaurant menu. I may make some new posts of code I have been using and you cant tell me if it's still efficient or anything has changed? 

Continuing what you showed me here,  without categories, it's odd that when I search <?php echo $label; ?>, there are no results to see what others are doing. What if I changed my list code to show the whole client table on one page and each showed their services? Is that getting into multiple arrays? Once I see it, I can usually adjust for what I need. 

Client 1

Service 1

Service 2

Client 2 

Service 1

Service 2

Service 3 

By daniel - February 7, 2020 - edited: February 7, 2020

Hi Rez,

That looks pretty good!

I think you can remove the line with the "continue" however, since $record['services:labels'] should already only contain services selected by that client record. So, you can try removing that line to see if you still get the same result. 

Cheers,

Daniel
Technical Lead
interactivetools.com

By rez - February 7, 2020

*facepalm*. I understand. Yes, that works well. Actually, this all means I don't even need the services list at the top. Thanks.