IF 2 checkboxes in the same field are checked

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 17, 2008   (RSS)

By benedict - December 16, 2008

Hi guys,

I have a situation with a checkbox field called course_type. For 95% of the hospitality courses in the database, I just present the result of this checkbox selection:

<?php echo $hospitalityRecord['course_type'] ?>

We have a rare situation that if the checkbox "Post Secondary Courses" AND "International Student Courses" are selected, we would like it to display "This course is available to both Local & International Students"

I started mucking around with it and got this far:

<?php if ($hospitalityRecord['course_type' = "Post Secondary Courses" and "International Student Courses"]): ?>
This course is available to both Local & International Students

else <?php echo $hospitalityRecord['course_type'] ?>
<?php endif ?>


Are you able to assist with the correct code?

Thanks,

Benedict

Re: [benedict] IF 2 checkboxes in the same field are checked

By Dave - December 17, 2008

Hi Benedict,

Are there 2 checkbox fields with different names or is it a multi-value list field displaying as checkboxes?

It's a little trickier with a multi value field because it stores both values together sepearted by tabs. Try this code:

<?php if (preg_match("/Post Secondary Courses/", $hospitalityRecord['course_type']) &&
preg_match("/International Student Courses/", $hospitalityRecord['course_type'])): ?>

This course is available to both Local &amp; International Students

<?php else: ?>
<?php echo $hospitalityRecord['course_type'] ?>
<?php endif ?>


Let me know if that works for you! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] IF 2 checkboxes in the same field are checked

By benedict - December 17, 2008

Works perfectly. Thanks, mate - you're the man.