![]() |
Store multiple values from select field in DB - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Store multiple values from select field in DB (/showthread.php?tid=42394) |
Store multiple values from select field in DB - El Forum - 06-06-2011 [eluser]heaversm[/eluser] I've got an HTML form which allows a user to select multiple options in a dropdown. I then pass that data on as post data to a CI model. How do I store the multiple values in CI? This is my current code (which only stores the last of the multiple selected values: Code: function edit_member() Store multiple values from select field in DB - El Forum - 06-06-2011 [eluser]cideveloper[/eluser] you need to pass $this->input->post('sel_dep') as an array Code: <select name="sel_dep[]" multiple="multiple"> I dont really know how you intend on storing the multiple values in the db. Do you have only one field to store all the info? are you going to serialize the array and store it that way? Store multiple values from select field in DB - El Forum - 06-06-2011 [eluser]heaversm[/eluser] Yes(?) - I don't have a lot of experience in this, but what I was assuming was that the comma delimited list of items would go into one field, and upon retrieval from the DB, I would parse that list out as separate items for display in the dropdown. Store multiple values from select field in DB - El Forum - 06-06-2011 [eluser]cideveloper[/eluser] You can use the below functions to serialize the form data, then load to filed in db and unserialize the db data and use the array in your forms Code: /** Store multiple values from select field in DB - El Forum - 06-06-2011 [eluser]heaversm[/eluser] Cool thanks. So one last question, in my model, do I refer to the field still as sel_dep, or must it now be sel_dep[] ? In other words, $v_memberdep = $this->input->post('sel_dep[]'); Oh, also, I want to replace commas, right, not slashes? |