View Full Version : Selected dropdownlist item - Call/Fetch data

03-09-2012, 05:15 PM
Hi All.

I have a dropdown list on a web form containing dates. My Question: How can I call data for that selected item(date) from a MySQL database and display it to the user? And more specifically, if that selected date has no data in the data base, I want to be able to display that as well.
I'm looking for a Javascript solution, and if possible a php solution.

Thank You!

03-09-2012, 05:40 PM
In your javascript code:
1)query the value of the input date
2)using ajax, post the value of step 1 to your php code
3)using ajax and a callback function, retrieve the MySQL data (preferably in JSON or XML format)
4)if a value of false is returned supplant an explanitory string into your data variable
5)insert data into your DOM

In your php code:
1)test the value sent from ajax, and strip, or convert any characters that could be used to exploit security holes
2)apply necessary conversions to the data so that it corresponds to how you structured your database
3)connect to your MySQL to retrieve the necessary records
4)if records are not already structured as JSON or XML, convert them to one of these formats for transmission
5)post the record back to your ajax on the clients browser

Your welcome

03-11-2012, 03:51 PM
Thank You Blaze 4218, I will try it and see if I can land it.