diotima Posted July 6, 2006 Share Posted July 6, 2006 Hi,I'm trying to use a multiple select box on a form so that more than one item may be selected and then have the value(s) written to MySQL. I'm able to trace the variables through one screen to the next, but I can't get it to write to the database correctly.What I have on the form ---[color=blue]<snip>// Select modules from modules table $query = "SELECT * FROM $table";$result = mysql_query($query);$num_results = mysql_num_rows($result);// Get/Set the ModuleID $mid = 'whatever'; // create query $ModuleNames= "Select * from Modules order by ModuleName asc"; // execute query $moduleresult = mysql_query($ModuleNames); <snip><?phpecho '<select name="Modules[]" class="cubufont" multiple="multiple">'; while($opt = mysql_fetch_array($moduleresult )) { echo '<option value="' . $opt['ModuleID'] . '"'; // Select the selected value echo ( $opt['ModuleID'] == $mid ) ? ' selected' : ''; echo '>'; echo $opt['ModuleName']; echo '</option>'; }echo '</select>'; ?>[/color]I can get the value(s) to appear on the next page via --[color=blue]$Modules=$_POST['Modules']; if ($Modules){ foreach ($Modules as $m){echo '',$m,',';} }[/color]But I'm stuck on how to get the value(s) into the MySQL tableI've used the serialize command like this --[color=blue]$ListModules=serialize($Modules);[/color]And then run the query to write this way -- [color=blue]mysql_query("INSERT INTO $table (Modules) VALUES ('$ListModules')[/color]But I'm left with the data input looking like this --a:2:{i:0;s:2:"71";i:1;s:2:"69";}What I really want is just to have 71,69 (for example) written to the table. Is this possible? I haven't had any luck with the unserialize.Thanks,Marie Quote Link to comment https://forums.phpfreaks.com/topic/13807-how-to-output-multiple-select-box-array-to-mysql/ Share on other sites More sharing options...
.josh Posted July 6, 2006 Share Posted July 6, 2006 $Modules = implode(",", $Modules); Quote Link to comment https://forums.phpfreaks.com/topic/13807-how-to-output-multiple-select-box-array-to-mysql/#findComment-53703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.