Link to related items with checkboxes

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

By Toledoh - May 22, 2013

Hi Guys,

Ive got a table of service; print, web, branding, packaging etc

I've got a table of portfolio items; job a, job b, job c etc

Within the portfolio, I'm selecting the service/s that apply to that job, and his allows me to display an icon for each (using the class to display the appropriate icon).

                <?php foreach ($record['services:labels'] as $icon): ?>
                <a href='services.php'><span class='sm<?php echo ($icon); ?>'></a></span>
                <?php endforeach ?>

I also have a combo page for the services - which is services.php.  How do I link to the specific detail page for each icon?

See http://freshrepublic.com.au/2013/portfolio.php and http://freshrepublic.com.au/2013/services.php, and I've attached the portfolio page

Cheers,

Tim (toledoh.com.au)
Attachments:

portfolio.php 4K

By gregThomas - May 23, 2013

Hi Tim,

If you're using the services num field for the value in the list field in the portfolio section, then this should work:

  $services = array_combine($record['services:values'], $record['services:labels']);

?>
<?php foreach ($services as $key => $service): ?>
  <a href='services.php?<?php echo urlencode($service).'-'.$key; ?>'><span class='sm<?php echo $service; ?>'></a></span>
<?php endforeach ?>

You should just be able to swap the code in your post for the code in this post. But this is example code, so you might have to make a few changes to get it working.

So the array_combine function creates an array where the values in the service field are used for the keys, and the labels are used for the values. Then I've modified your code so that the foreach loop cycles through the services array and creates a link to the correct services page using the key and value. The url encode function ensures that any special charters or spaces get converted for use in a URL. 

Let me know if you have any questions.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com