Multi-select to individual links

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 23, 2016   (RSS)

Hi Guys,

I would have thought this easy, but I can't get my head around it.

I've got a multi select "category" field in the "blog" table.  It is just within the section, not referencing another table.  ie. 1|news, 2|travel, 3|events etc.

How do I get a list of those categories (not per record, but in entirety) to create a menu. ie. <a href="?1">news</a> <a href="?2">travel</a> <a href="?3">events</a> 

Cheers,

Tim (toledoh.com.au)

Hey Tim,

Here is how I'd do it:

  <?php $categories = getListOptions('blog', 'category');  ?>

  <?php foreach ($categories as $value => $label): ?>
    <a href="?<?php echo htmlEncode($value); ?>"><?php echo htmlEncode($label); ?></a> 
  <?php endforeach; ?>

The getListOptions will return a drop downs options, with the key being the value, and the value being the label. You can then cycle through these and create a link with the value in url.

Let me know if you have any questions. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com