how to retrieve the values of mulple list? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: how to retrieve the values of mulple list? (/showthread.php?tid=5326) |
how to retrieve the values of mulple list? - El Forum - 01-17-2008 [eluser]Nagabhushana[/eluser] how to retrieve the values of mulple list? example html code is follows <select class= "box-small13" id="community[] " name="community[]" size=5 multiple style='width:150px';> <option value=item1 >item1</option> <option value=item2 >item2</option> <option value=item3 >item3</option> <option value=item4 >item4</option> <option value=item5 >item5</option> <option value=item6 >item6</option> <option value=item7 >item7</option> </select> thank u how to retrieve the values of mulple list? - El Forum - 01-17-2008 [eluser]xwero[/eluser] Code: print_r($_POST['community']) how to retrieve the values of mulple list? - El Forum - 01-17-2008 [eluser]tonanbarbarian[/eluser] Code: $this->input->post('community'); how to retrieve the values of mulple list? - El Forum - 01-17-2008 [eluser]jcopling[/eluser] Yeah I would typically do something like this: Code: $list = $this->input->post('community'); how to retrieve the values of mulple list? - El Forum - 01-18-2008 [eluser]xwero[/eluser] [quote author="jcopling" date="1200631253"]Yeah I would typically do something like this: Code: $list = $this->input->post('community'); a foreach loop takes less time and variables to do the same thing. how to retrieve the values of mulple list? - El Forum - 01-18-2008 [eluser]jcopling[/eluser] It's true that a foreach loop is more efficient. But I find that when I need multiple values from a form post, I need it for more than one corresponding fields. So it's just as easy to do something like this: Code: $community = $this->input->post('community'); But you're absolutely correct. If you are only needing to loop through 1 set of values a foreach loop would be preferable. how to retrieve the values of mulple list? - El Forum - 01-18-2008 [eluser]xwero[/eluser] This is what i do when i need to handle several equal length arrays Code: $community = $this->input->post('community'); btw using the count function every time the loop restarts isn't good for performance. This is better: Code: for($i=0, $max = count($community); $i<=$max;$i++){ Foreach is not absolute performance but i think flexibility is a big issue too. But of course everyone has his/her own style. how to retrieve the values of mulple list? - El Forum - 01-18-2008 [eluser]jcopling[/eluser] Good points. I'll have to give this method a try. |