Forums

PHP

This topic is locked

Need MySQL set to populate checkbox group for update record

Posted 03 Mar 2010 02:40:55
1
has voted
03 Mar 2010 02:40:55 Robert Robinette posted:
I have an insert record form that contains a checkbox group called "servicesID". This checkbox group contains checkboxes labeled as services for a construction project (architecture, plumbing, electrical, etc) that are entered into a field in a db record as a set. I can insert the record without a problem - the set in the record contains the comma-separated values as a string. I did this by imploding the data to create the string.

The problem is that I now want to create an update record form and I want the checkboxes to populate with the values from the MySQL set but I'm not sure how to do this. I'm guessing i need to "explode" them somehow? But I'm not sure at all how to do this.

Any help would be appreciated. Thanks for looking.

Replies

Replied 19 Mar 2010 10:29:34
19 Mar 2010 10:29:34 Roddy Dairion replied:
You're right using explode if you've stored the data as csv's is the best way to do this.
$data=explode(",",$row['fieldname']);
//replacing fieldname with your you own
foreach($data as $value)
{
  echo "<option value=\"$value\">$value</option>"
}

placing this inside your <select> tag should normally work.

Reply to this topic