littlejones
11-15-2006, 10:39 AM
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[0] = "General";
$categoryImmigration = mysql_result($result,$i,'categoryImmigration');
if ($categoryImmigration == "yes") $category[1] = "Immigration Team";
$categoryHousing = mysql_result($result,$i,'categoryHousing');
if ($categoryHousing == "yes") $category[2] = "Housing Team";
$categoryEmployment = mysql_result($result,$i,'categoryEmployment');
if ($categoryEmployment == "yes") $category[3] = "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[0].", ".$category[1].", ".$category[2].", ".$category[3];
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!! :o
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[0] = "General";
$categoryImmigration = mysql_result($result,$i,'categoryImmigration');
if ($categoryImmigration == "yes") $category[1] = "Immigration Team";
$categoryHousing = mysql_result($result,$i,'categoryHousing');
if ($categoryHousing == "yes") $category[2] = "Housing Team";
$categoryEmployment = mysql_result($result,$i,'categoryEmployment');
if ($categoryEmployment == "yes") $category[3] = "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[0].", ".$category[1].", ".$category[2].", ".$category[3];
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!! :o