Display if something is from a checkbox multi value list

5 posts by 2 authors in: Forums > CMS Builder
Last Post: October 11, 2009   (RSS)

By (Deleted User) - October 8, 2009 - edited: October 9, 2009

Hello,

I am building a site that has a number of tours. I would like to include a flag for each of the countries the tour travels through.

I previously used:

<?php if ($guided_tourRecord['tour_location'] == 'uk'): ?>
<span>This is some flag html for the uk</span>
<?php elseif ($guided_tourRecord['tour_location'] == 'us'): ?>
<span>This is some flag html for the us</span>
<?php else: ?><?php endif ?>


That was fine when I used a pulldown list where you could only select one country. How would I make this list 'if' from the checkboxes multi value list?

Thanks Jono

Re: [jonoc73] Display if something is from a checkbox multi value list

By Chris - October 11, 2009

Hi Jono,

You can use the same technique from [url http://www.interactivetools.com/forum/gforum.cgi?post=74818#74818]this post[/url].

Alternately, if all your countries are going to display the same HTML but with a different IMG SRC URL, you could do something like this to list them all:

<?php foreach (explode("\t", trim($guided_tourRecord['tour_location'])) as $countryCode): ?>
<img src="images/flag_<?php echo htmlspecialchars($countryCode) ?>.gif" />
<?php endforeach ?>


I hope this helps. Please let us know if you have any questions or comments.
All the best,
Chris

Re: [jonoc73] Display if something is from a checkbox multi value list

By Chris - October 11, 2009

Hi Jono,

Can you please post the PHP source code for the page in question?
All the best,
Chris

Re: [chris] Display if something is from a checkbox multi value list

By Chris - October 11, 2009

Hi Jono,

I took a look at the URL you PMed me and I think I've figured out what you want.

To limit the number of flags displayed, you can add a counter and "break" out of the foreach when your counter gets to a certain number. For example,
<?php $count = 1; ?>
<?php foreach (explode("\t", trim($guided_tourRecord['tour_location'])) as $countryCode): ?>
<?php if ($count > 2) { break; } ?>
<img src="images/flag_<?php echo htmlspecialchars($countryCode) ?>.gif" />
<?php $count++; ?>
<?php endforeach ?>


Does that do what you want? Please let me know if you have any questions.
All the best,
Chris