Create multidimensional array from two database tables for form_dropdown() - 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: Create multidimensional array from two database tables for form_dropdown() (/showthread.php?tid=43809) |
Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-24-2011 [eluser]suntrop[/eluser] I need a multidimensional array for a nested select field with form_dropdown(). I've got two tables, the first (customers) are for the optgroups. The seccond table holds all projects. Currently my code looks like this … Code: $this->db->select(' But that code produces just a normal array. How can I turn it into a multi array to user with form_dropdown()? Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-24-2011 [eluser]cpass78[/eluser] Might need two queries, try something like this, might not be functional, basically creating a new array( $rows ) containing arrays of the results: Code: $this->db->select( 'c.id AS customer_id, c.name AS customer_name' ); Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-24-2011 [eluser]suntrop[/eluser] Thanks for your help. I don't know if I made something wrong, but it doesn't work as expected. I get an array like this … Code: Array What I need for from_dropdown() is … Code: Array Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-24-2011 [eluser]cpass78[/eluser] Oh i see, well if the result you poseted was from the code I gave you, it worked perfectly, just formatted wrong. Youll need to build you own array in this case. *Thinks something like this will work. Not done yet have to think about this a bit, give me a min Code: $this->db->select( 'c.id AS customer_id, c.name AS customer_name' ); Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-24-2011 [eluser]suntrop[/eluser] I think I get it. With a Little Help from My Friends :-) Thanks cpass78 Code: $this->db->select( 'p.id AS project_id, p.title AS project_title, c.name AS customer_name' ); It produces … Code: <select name="projects"> Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-24-2011 [eluser]cpass78[/eluser] No sweat, yeah arrays can get a bit messy like that, I wonder if returning $this->db->result() would have been a bit cleaner since its an object.. Anyhow glad its working. Create multidimensional array from two database tables for form_dropdown() - El Forum - 07-25-2011 [eluser]suntrop[/eluser] Thanks for the hint. I'll change it to an object. |