I have a selection box with a list of items. When the user selects a certain item, i need to do a search in the mysql database and find a match. How do i do this???
Name of the combo box or selection box acts as a variable that you need to specify in your sql query. for example: your html should look like this: <select name="items" id="items"> <option value="item1">item1</option> <option value="item2">item2</option> </select> Code (markup): and your SQL Query: $query = mysql_query("SELECT * FROM table_name where filed_name = '$items'"); $result = mysql_fetch_assoc($query); PHP:
Yah i have that, but how would i register the callback for the onchange so that it can execute the php code? My combo box will need an OnChange method() or something similar, no?
You can submit the form on OnChange event e.g. <select name="items" onChange="this.form.submit()"> Set the form action to the same page or the page where your php script is
Submitting a form using a select box would be quite annoying for a user I think. Imagine if you select the wrong option and the form submits without you wanting it to - it would upset me anyway........ Maybe try using AJAX to collect the data from the database without actually submitting the form?
Dave487, you're right, it is rather annoying. I don't want to submit the form when the user has selected an option from the selection box. you mentioned using AJAX, i've never heard of it, let alone know how to use it...could you please point me in the right direction...someone. Thanks.