Maarten_ Posted July 4, 2011 Share Posted July 4, 2011 Hello. I'm having some problem at the moment. Wath i want, there is a form with 2 fields. Field 1 and 2. Field 1 is a drop down list, the values are selected from the database. Depending on the choise from field 1, I want to edit the query from field 2. So to give an example, if the user set the value of field 1 to lol, the query to pick the data that can be used in field 2 should be like select * from table where .. = lol The meaning of the query in the second field is to use ajax and create a suggestion list for the user so only. I hope someone is able to help me. Quote Link to comment https://forums.phpfreaks.com/topic/241050-variable-query-depending-on-field-filled-in/ Share on other sites More sharing options...
monkeytooth Posted July 4, 2011 Share Posted July 4, 2011 Well you are right, you will need to implement the AJAX if you want to pull this off without reloading the page to do it. If you already know how to make your queries to mySQL via PHP then you are all set there in order to do work with AJAX you generally don't have to change how you work with your php, aside from how you output your data at the end of the run of the script. Meaning you generally leave it as raw as needed for sending back to the JavaScript so it can process the data and do with it as needed. my suggestion to you is the same as I would say to anyone else wanting to pick up and start using AJAX. go out, grab the latest copy of the jQuery Library which is a extremely easy, stable, and expandable JavaScript library. It will make your life so much easier in the long run not having to worry as much about things like cross browser support and all else. And with that I will follow it up with. When you get the jQuery Lib set up on your site.. google "jquery post()" "jquery each() and json" and find examples about those 2 particular things to implement what you are asking here. Quote Link to comment https://forums.phpfreaks.com/topic/241050-variable-query-depending-on-field-filled-in/#findComment-1238145 Share on other sites More sharing options...
Maarten_ Posted July 4, 2011 Author Share Posted July 4, 2011 Okay, thanks a lot for your quick respons. I will take a look at it now. Quote Link to comment https://forums.phpfreaks.com/topic/241050-variable-query-depending-on-field-filled-in/#findComment-1238162 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.