Here's one for you...
I have a form with 4 checkboxes. When the form is submitted those that are checked are stored in the database in 4 separate fields as "yes" or left null if they were not checked.
So, I then want to display on a page the categories (checkboxes) that the person has checked. Obviously I want to separate these with a comma or an & sign. However I don't want a comma or & sign to appear if part of the array is empty. So as an example...
4 categories: General, Immigration, Housing, Employment.
The user checks Immigration and Employment. These are stored in the database in fields categoryImmigration and categoryEmployment with the record "yes" and the other two (categoryGeneral and categoryHousing) are left blank.
I now want to display the categories on a page in the format... Immigration Team, Employment Team.
So I SELECT * FROM the table with these fields in. I store the results as follows...
$categoryGeneral = mysql_result($result,$i,'categoryGeneral');
if ($categoryGeneral == "yes") $category = "General";
$categoryImmigration = mysql_result($result,$i,'categoryImmigration');
if ($categoryImmigration == "yes") $category = "Immigration Team";
$categoryHousing = mysql_result($result,$i,'categoryHousing');
if ($categoryHousing == "yes") $category = "Housing Team";
$categoryEmployment = mysql_result($result,$i,'categoryEmployment');
if ($categoryEmployment == "yes") $category = "Employment Team";
That's fine, and now I have the result stored in the array $category
I then need to display on the page. As you can now see, I can't do it in the following way, because if a user didn't select one of the checkboxes there would be a redundant comma..
echo $category.", ".$category.", ".$category.", ".$category;
In this example, the following would be displayed on the page...
, Immigration Team, , Employment Team
Obviously unacceptable. How can I get around this?
Thanks a million in advance I have a deadline to meet!!