sonofjorel Posted January 19, 2011 Share Posted January 19, 2011 I have a table in a database that I need to filter upon using dependent select boxes. The database was poorly designed and would be difficult to break into separate tables without affecting code written in other places. I have found some good code and understanding of how to implement the dependent select boxes if you have two tables with one column functioning as a lookup value between the two. I have provided a short bit of sql of what the table looks like with some column names changed. I would need to first sort by lastname and have firstname dependent on the selection of lastname. Any help would be greatly appreciated. create table `user` ( `id` int(3) Not Null Auto_increment, `firstname` varchar (60), `lastname` varchar (24), `age` double , `hometown` varchar (75), `job` varchar (75), `birthdate` date ); insert into `user` (`id`, `firstname`, `lastname`, `age`, `hometown`, `job`, `birthdate`) values ('1','Peter','Griffin','41','Quahog','Brewery','1960-01-01'), ('2','Lois','Griffin','40','Newport','Piano Teacher','1961-08-11'), ('3','Joseph','Swanson','39','Quahog','Police Officer','1962-07-23'), ('4','Glenn','Quagmire','41','Quahog','Pilot','1960-02-28'), ('5','Megan','Griffin','16','Quahog','Student','1984-04-24'), ('6','Stewie','Griffin','2','Quahog','Dictator','2008-03-03'); Quote Link to comment https://forums.phpfreaks.com/topic/224985-dynamic-dependent-select-box-with-one-table/ Share on other sites More sharing options...
webbhelp Posted January 19, 2011 Share Posted January 19, 2011 How do you mean by have firstname dependent on lastname? Quote Link to comment https://forums.phpfreaks.com/topic/224985-dynamic-dependent-select-box-with-one-table/#findComment-1162087 Share on other sites More sharing options...
sonofjorel Posted January 19, 2011 Author Share Posted January 19, 2011 after lastname is selected, then the first names associated with that name are present in the firstname select box. i.e. if Griffin is chosen as a last name, then only peter, lois, megan and stewie are selectable in the firstname select box Quote Link to comment https://forums.phpfreaks.com/topic/224985-dynamic-dependent-select-box-with-one-table/#findComment-1162120 Share on other sites More sharing options...
webbhelp Posted January 19, 2011 Share Posted January 19, 2011 Do you mean have to do that? Use AJAX, And send the chosen name to the php file which is Selecting, the firstnames and put it into a select box Quote Link to comment https://forums.phpfreaks.com/topic/224985-dynamic-dependent-select-box-with-one-table/#findComment-1162126 Share on other sites More sharing options...
sonofjorel Posted January 19, 2011 Author Share Posted January 19, 2011 there in lies my problem. I understand what technologies are involved with this, I am just unclear how to go about using php and AJAX with one table to filter out the results. If I could use two tables as shown below, I would not have an issue. Thanks create table `lname` ( `id` int(3) Not Null Auto_increment, `lastname` varchar (24) ); insert into `lname` (`id`, `lastname`) values ('1', 'Griffin'), ('2', 'Quagmire'), ('3', 'Swanson'); create table `fname` ( `id` int(3) Not Null, `firstname` varchar (60) ); insert into `fname` (`id`, `firstname`) values ('1','Peter'), ('1','Lois'), ('3','Joseph'), ('2','Glenn'), ('1','Megan'), ('1','Stewie'); Quote Link to comment https://forums.phpfreaks.com/topic/224985-dynamic-dependent-select-box-with-one-table/#findComment-1162221 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.