Working with Multi-Select & Dropdowns and SQL |
[eluser]Bionicjoe[/eluser]
I'm really not much of a coder but CI is getting me places. However I am lost on using multi-select fields and dropdowns. I think I'm good on dropdowns for now. I have the multi-select fields and I can select an item and submit to the db table and repop the form with that value to edit. However I can only store one item. Choosing 2 or more items I usually get the first item selected. I'm just storing the values as text in my table. I can't find a good tutorial or info on multi-selects & SQL. Usually just find basic info on creating the field. Any help is greatly appreciated.
[eluser]Philipp Gérard[/eluser]
Code: <select name="lineup[]" multiple="multiple"></select>
[eluser]Bionicjoe[/eluser]
Thanks, that works, but I get this error now. Code: Unknown column 'Array' in 'field list' What should I change to get the values out of that nested array?
[eluser]Abdul Jamal[/eluser]
$values=$this->input->post('lineup'); you can check output of $values. print_r($values);
[eluser]Philipp Gérard[/eluser]
Compare: http://php.net/manual/en/language.types.array.php
[eluser]Bionicjoe[/eluser]
I did this. Code: function updateoutage() But it dumps out these values. Code: UPDATE `outage` SET `outageid` = '1', ...blah... `servicename` = 'V', `location` = 'L', ... (Plus I got this error: Duplicate entry '1' for key 'PRIMARY'...grrr SQL)
[eluser]Philipp Gérard[/eluser]
We are talking at cross purposes here I believe. You want to have a multi-select dropdown where a user can select more than one entry. You now want to access these entries that the user selected to use them in some way (for instance in a database query). 1. Create a select like this: <select name="lineup[]" multiple="multiple"></select> 2. Add options: <option value="x">y</option> 2. Access the ARRAY of submitted data from this select: $array = $this->input->post('lineup'); 4. Use print_r($array) to see how the array is composed.
[eluser]Bionicjoe[/eluser]
I'm creating the multi-select just fine in the form. I'm just having a problem extracting it from the form, or specifically the Array in the POST data.
[eluser]Philipp Gérard[/eluser]
Please post the output of print_r($array); so that I can tell you how to extract the desired information from the array.
[eluser]Bionicjoe[/eluser]
Code: Array ( This is how I get the above array. Code: if (is_array($_POST)) Servicename & location cause problems in the SQL UPDATE statement because they are arrays. Quote:Unknown column 'Array' in 'field list' |
Welcome Guest, Not a member yet? Register Sign In |