Dynamic dependant dropdown from database |
Hi All,
I desperately need a dynamic dependant dropdown from database. This code works brilliantly - http://www.99points.info/2010/12/n-level...x-and-php/ But I can't get it to work in Codeigniter. Can anyone convert it for me please? Yours Roy Bee Creative Web Design www.bcwd.ltd.uk
If you share some code, I'm sure you'll get some feedback, but it's hard to help when we don't know what mistakes you are making.
It's not so much my mistakes, it's converting the PHP to Codeigniter, I think a lot of the trouble is with the Ajax?
Yours Roy Bee Creative Web Design www.bcwd.ltd.uk
I recommend reading the CodeIgniter documentation, especially the parts about controllers, database connections, and database queries. Even if you skim those sections, you'll have a better understanding of what to do. You should be aware that the code you've been looking at is very old, and legacy code like that is not optimal, unless you are just learning.
(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!
(12-26-2015, 12:03 PM)skunkbad Wrote: I recommend reading the CodeIgniter documentation, especially the parts about controllers, database connections, and database queries. Even if you skim those sections, you'll have a better understanding of what to do. You should be aware that the code you've been looking at is very old, and legacy code like that is not optimal, unless you are just learning. I'm fine with the CI stuff and I can get the first dropdown working, but something needs doing to the Ajax code (which I'm not good at) to make the second etc dropdowns to work. That's why I'm asking for help? Yours Roy Bee Creative Web Design www.bcwd.ltd.uk
In jQuery ever element in html needs to have an ID also I like to give each element a Name
For one that jQuery code is using an out dated jQuery build. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(12-27-2015, 06:09 AM)InsiteFX Wrote: In jQuery ever element in html needs to have an ID also I like to give each element a Name I understand this is old code, and I have tested it with - <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> - and it works perfectly BUT, I don't understand enough about JQuery to get it to work in CI, so I need some help please? I can't get the second dropdown to work, and I don't know why? Yours Roy Bee Creative Web Design www.bcwd.ltd.uk (12-27-2015, 07:49 AM)GingerNut Wrote: BUT, I don't understand enough about JQuery to get it to work in CI, so I need some help please? I know only a little Javascript, but I don't think there's anything special to get it working "in CI" because PHP doesn't interact with Javascript. By the time Javascript is ready to run, PHP has already finished. Can you get any Javascript to work in a page generated by CI? Conversely, does the Javascript code you have work ok in a regular HTML page you create by hand with just a few dropdowns? Edit: I just found this. It may help. http://stackoverflow.com/questions/20483...enu-values
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!
I have recently installed an Ajax Search routine and noted in the tutorial the CI problem and solution.
http://www.johns-jokes.com/downloads/sp-...ax-search/ |
Welcome Guest, Not a member yet? Register Sign In |