This is a forum where members new and old can come to ask questions and get info and opinions. It is not a place to advertise your business or have other forms of advertising, whether it be in your posts or signature.

All links in the forum will not be indexed by Search Engines and any unapproved forms of advertising or spam will be dealt with accordingly, deleted, and that member's account banned.

Forums

Overview » PHP » Need MySQL set to populate checkbox group for update record
Reply

Need MySQL set to populate checkbox group for update record

Robert Robinette
Member



Since: 11 Nov 2005
Posts: 31
Posted 03 Mar 2010 02:40:55

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.

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.
Roddy Dairion
Zone Manager



Since: 12 Oct 2005
Posts: 441
Replied 19 Mar 2010 10:29:34
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

Message
Reply
Follow us on Facebook Follow us on twitter Subscribe to the RSS feed
Activate your free membership today | Login | Currency