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)

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: [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