Modifying lists (checkbox multi-value) to display value and label differently

5 posts by 2 authors in: Forums > CMS Builder
Last Post: July 10, 2013   (RSS)

By meg - July 10, 2013

With a multi-listing record, I created a list (checkbox multi-value) that's referencing another database table, with a different value and label. I'm happy with the results displaying the value in a comma delineated view, but not with the label. 

This is how it's currently displaying: 

PHP

<a href="#" class="<?php echo join(', ', $record['ingredients:labels']); ?>"><?php echo join(', ', $record['ingredients:values']); ?></a>

HTML

<a href="#" class="coconut, bananas, dates, vanilla, cashew">Thai Coconut, Banana, Dates, Vanilla, Cashew Milk</a>

Essentially, I need the results to view as such:

<a href="#" class="coconut">Thai Coconut</a>, <a href="#" class="bananas">Banana</a>, <a href="#" class="dates">Dates</a>, <a href="#" class="vanilla">Vanilla</a>, <a href="#" class="cashew">Cashew Milk</a>

What modifications do I need to make to the PHP so the HTML displays this way? Thanks so much!

By meg - July 10, 2013

Sounds good, but I plugged it in and got these errors.

At the top: Notice: Undefined variable: record in /home/content/88/11310188/html/menu-and-pricing.php on line 92 Notice: Undefined variable: record in /home/content/88/11310188/html/menu-and-pricing.php on line 92 Warning: array_combine() expects parameter 1 to be array, null given in /home/content/88/11310188/html/menu-and-pricing.php on line 92

Where the ingredients are suppose to be listed: 

Warning: Invalid argument supplied for foreach() in /home/content/88/11310188/html/menu-and-pricing.php on line 169 

Any thoughts?

By gregThomas - July 10, 2013

Hi Meg,

You are getting the first error because where you have added the array_combine code the $record variable hasn't been created yet, then the second foreach error is being created as the ingredients array hasn't been created. Try adding the entire block of code where you want the links to display, as the $record variable should definitely have been created at that point. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By meg - July 10, 2013

Works like a charm - thank you!!