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: [chris] Display if something is from a checkbox multi value list

By (Deleted User) - October 11, 2009

Chris, once again this is great and has reduced the amount of code in my page by about 15 lines...

As you have probably guessed by now I have been building a tour guide site. I am displaying flags with this method for the countries the tour travels through. However, I am running into a little bother when it comes to US states. It's obviously displaying a nice US flag for each state - is there a way to limit the amount of flags listed to 2?

I can supply a url link to you personally if you like??

Thanks Jono.

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