Smartest way to build an HTML select - 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: Smartest way to build an HTML select (/showthread.php?tid=60413) |
Smartest way to build an HTML select - El Forum - 03-21-2014 [eluser]IFR70[/eluser] Hi all, I'm a beginner in PHP and Codeigniter, so please apologize if my question is very basic. I have two tables like these: The first table name is "friends" and the columns are: - ID_friend (int) - Name (varchar(50)) - Surname (varchar(50)) - ID_nation (int) The second table is "nation" and the columns are: - ID_nation (int) - Nation_name (varchar(50)) OK, now I have to build a form to insert a record on the table "friends", but I want to decode the field "ID_nation" with all the "Nation_name"s of the second table. In my model I have this function: Code: function listColumns() The array returned by this function is this one: Code: Array Is there a smart way to substitute ID_nation with the list of the nations in the second table, so when I pass the array to the view I can easily build an HTML SELECT? Cheers. Smartest way to build an HTML select - El Forum - 03-21-2014 [eluser]InsiteFX[/eluser] See the CodeIgniter Form_helper Smartest way to build an HTML select - El Forum - 03-21-2014 [eluser]IFR70[/eluser] Thank you for the answer, InsiteFX. I apologize but I'm a true beginner, so your tip it's not really clear for me. I've read the CodeIgniter Form_helper, and I use this helper to build forms, but I'm not sure if I understood how I can easily read the nations values to build the select. The only one way I can imagine is to add to the array $fields the result of: Code: select Nation_name from nation and then use the form_dropdown() within the view... is it correct? Smartest way to build an HTML select - El Forum - 03-21-2014 [eluser]InsiteFX[/eluser] Yes, you need to build the array for the dropdown like so. This can come from a database etc; Code: $data = array( Example for a Month's array. Code: $data = array( Smartest way to build an HTML select - El Forum - 03-21-2014 [eluser]IFR70[/eluser] Thank you very much. |