Dynamic dependant dropdown from database |
(12-26-2015, 08:58 AM)GingerNut Wrote: I desperately need a dynamic dependant dropdown from database. Hey, there. I just implemented that. Check out my Search Scraper application on GitHub. The basic idea is this. In your controller, load from the database the values that will populate the dropdown, and then pass those values to your view, which will then use them when building the dropdown. In my controller's constructor, I do this: PHP Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); The call to get_sites() in my model executes this code: PHP Code: public function get_sites() Now that I have the array $sites holding the sites I have in the database, I pass it to the view: PHP Code: $data = array( And then my view goes and does this: PHP Code: <select id="sites" name="search[site_id]"> I hope that's a good example, but if it's not clear, please let me know where it derails. Good Luck!
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
|
Messages In This Thread |
Dynamic dependant dropdown from database - by GingerNut - 12-26-2015, 08:58 AM
RE: Dynamic dependant dropdown from database - by skunkbad - 12-26-2015, 10:03 AM
RE: Dynamic dependant dropdown from database - by GingerNut - 12-26-2015, 10:08 AM
RE: Dynamic dependant dropdown from database - by skunkbad - 12-26-2015, 12:03 PM
RE: Dynamic dependant dropdown from database - by GingerNut - 12-27-2015, 03:04 AM
RE: Dynamic dependant dropdown from database - by RobertSF - 12-26-2015, 04:29 PM
RE: Dynamic dependant dropdown from database - by InsiteFX - 12-27-2015, 06:09 AM
RE: Dynamic dependant dropdown from database - by GingerNut - 12-27-2015, 07:49 AM
RE: Dynamic dependant dropdown from database - by RobertSF - 12-27-2015, 01:27 PM
RE: Dynamic dependant dropdown from database - by John_Betong - 12-27-2015, 05:40 PM
|