Ashley Martin
Ashley Martin

Reputation: 35

How do I input multiple values that are comma-separated into a table?

Disclaimer: I am completely new to PHP and MySQL/SQL.

I have multiple implode()functions for my arrays. I want to be able to have the arrays input into the table separated with commas to avoid confusion.

  $company_state = implode($_POST['companystate']);

The output looks like this in the table and when echo:

Company state: ILMEMDNVOHOK

But I want it to look like this within the table:

Company state: IL, ME, MD, NV, OH, OK

Is there any way I can get it to do this?

Here is the code for the form:

<label for="companystate[ ]">Company state:</label><br />

<input type="checkbox" name="companystate[ ]" value="AL"  /><strong>Alabama</strong><br />
<input type="checkbox" name="companystate[ ]" value="AK"  /><strong>Alaska</strong><br />
<input type="checkbox" name="companystate[ ]" value="AZ"  /><strong>Arizona</strong><br />
<input type="checkbox" name="companystate[ ]" value="AR"  /><strong>Arkansas</strong><br />
<input type="checkbox" name="companystate[ ]" value="CA"  /><strong>California</strong><br />
<input type="checkbox" name="companystate[ ]" value="CO"  /><strong>Colorado</strong><br />
<input type="checkbox" name="companystate[ ]" value="CT"  /><strong>Connecticut</strong><br />
<input type="checkbox" name="companystate[ ]" value="DE"  /><strong>Delaware</strong><br />
<input type="checkbox" name="companystate[ ]" value="DC"  /><strong>District of Columbia</strong><br />
<input type="checkbox" name="companystate[ ]" value="FL"  /><strong>Florida</strong><br />
<input type="checkbox" name="companystate[ ]" value="GA"  /><strong>Georgia</strong><br />
<input type="checkbox" name="companystate[ ]" value="HI"  /><strong>Hawaii</strong><br />
<input type="checkbox" name="companystate[ ]" value="ID"  /><strong>Idaho</strong><br />
<input type="checkbox" name="companystate[ ]" value="IL"  /><strong>Illinois</strong><br />
<input type="checkbox" name="companystate[ ]" value="IN"  /><strong>Indiana</strong><br />
<input type="checkbox" name="companystate[ ]" value="IA"  /><strong>Iowa</strong><br />
<input type="checkbox" name="companystate[ ]" value="KS"  /><strong>Kansas</strong><br />
<input type="checkbox" name="companystate[ ]" value="KY"  /><strong>Kentucky</strong><br />
<input type="checkbox" name="companystate[ ]" value="LA"  /><strong>Louisiana</strong><br />
<input type="checkbox" name="companystate[ ]" value="ME"  /><strong>Maine</strong><br />
<input type="checkbox" name="companystate[ ]" value="MD"  /><strong>Maryland</strong><br />
<input type="checkbox" name="companystate[ ]" value="MA"  /><strong>Massachusetts</strong><br />
<input type="checkbox" name="companystate[ ]" value="MI"  /><strong>Michigan</strong><br />
<input type="checkbox" name="companystate[ ]" value="MN"  /><strong>Minnesota</strong><br />
<input type="checkbox" name="companystate[ ]" value="MS"  /><strong>Mississippi</strong><br />
<input type="checkbox" name="companystate[ ]" value="MO"  /><strong>Missouri</strong><br />
<input type="checkbox" name="companystate[ ]" value="MT"  /><strong>Montana</strong><br />
<input type="checkbox" name="companystate[ ]" value="NE"  /><strong>Nebraska</strong><br />
<input type="checkbox" name="companystate[ ]" value="NV"  /><strong>Nevada</strong><br />
<input type="checkbox" name="companystate[ ]" value="NH"  /><strong>New Hampshire</strong><br />
<input type="checkbox" name="companystate[ ]" value="NJ"  /><strong>New Jersey</strong><br />
<input type="checkbox" name="companystate[ ]" value="NM"  /><strong>New Mexico</strong><br />
<input type="checkbox" name="companystate[ ]" value="NY"  /><strong>New York</strong><br />
<input type="checkbox" name="companystate[ ]" value="NC"  /><strong>North Carolina</strong><br />
<input type="checkbox" name="companystate[ ]" value="ND"  /><strong>North Dakota</strong><br />
<input type="checkbox" name="companystate[ ]" value="OH"  /><strong>Ohio</strong><br />
<input type="checkbox" name="companystate[ ]" value="OK"  /><strong>Oklahoma</strong><br />
<input type="checkbox" name="companystate[ ]" value="OR"  /><strong>Oregon</strong><br />
<input type="checkbox" name="companystate[ ]" value="PA"  /><strong>Pennsylvania</strong><br />
<input type="checkbox" name="companystate[ ]" value="RI"  /><strong>Rhode Island</strong><br />
<input type="checkbox" name="companystate[ ]" value="SC"  /><strong>South Carolina</strong><br />
<input type="checkbox" name="companystate[ ]" value="SD"  /><strong>South Dakota</strong><br />
<input type="checkbox" name="companystate[ ]" value="TN"  /><strong>Tennessee</strong><br />
<input type="checkbox" name="companystate[ ]" value="TX"  /><strong>Texas</strong><br />
<input type="checkbox" name="companystate[ ]" value="UT"  /><strong>Utah</strong><br />
<input type="checkbox" name="companystate[ ]" value="VT"  /><strong>Vermont</strong><br />
<input type="checkbox" name="companystate[ ]" value="VA"  /><strong>Virginia</strong><br />
<input type="checkbox" name="companystate[ ]" value="WA"  /><strong>Washington</strong><br />
<input type="checkbox" name="companystate[ ]" value="WV"  /><strong>West Virginia</strong><br />
<input type="checkbox" name="companystate[ ]" value="WI"  /><strong>Wisconsin</strong><br />
<input type="checkbox" name="companystate[ ]" value="WY"  /><strong>Wyoming</strong><br />

Thanks in advance. And also could you explain to me what each function does? I'm still learning and most of PHP/SQL is still gibberish to me.

Upvotes: 1

Views: 2948

Answers (2)

paulsm4
paulsm4

Reputation: 121869

Try this:

$company_state = implode(",", $_POST['companystate']);

Upvotes: 1

Rylab
Rylab

Reputation: 1295

You just need to pass in some glue for your implode:

implode(', ', $_POST['companystate']);

Upvotes: 1

Related Questions