Hi All,
I want to include a list (combo) box that allows multiple choices.. that is populated from the database.
I have used the code: (this is just a snippet from my overall code).
// ***** populate the mods list
$result = mysql_query("SELECT * FROM ccentral_mods ORDER BY MOD_NAME",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<select name=\"mods[]\" size=\"2\" multiple>";
do {
printf("<option value=\"%s\">\n", $myrow["MOD_NAME"]);
echo $myrow["MOD_NAME"];
echo "</option>";
}
while ($myrow = mysql_fetch_array($result));
echo "</select>\n";
}
else {
echo "<input type=\"text\" name=\"type\" size=\"30\" maxlength=\"30\">";
}
// **** end population
This results in the following format being printed:
<select name="mods[]" size="2" multiple>
<option value="Something">Something</option>
<option value="A Thing">A Thing</option>
<option value="SomethingElse">SomethingElse</option>
</select>
Which I think is how it should be??
Now, what I'm completely stumped at.. and I cant find anything about it (anywhere)..
Is how do I get this into a database?
If this is the only form element on the page, what is the format of the sql to input the data into the db, preferably seaparated by a comma (,).
For example is I selected:
Something
A Thing
How would I get
Something, A Thing
into the database?
Is it just as simple as...
mysql_query("INSERT INTO table_name (the_column) VALUES ('$mods[]')");
And how would this separate the items of the array by the comma?
Regards
Lee