AasimAzam Posted March 25, 2014 Share Posted March 25, 2014 (edited) Hi,I have a list of football results in a MYSQL database and have written a function to access whatever I need from it. I would like to use this in conjunction with a drop down list. $query1 = query_create('cristiano', '$season', '$year', '$competition', '$level', 'Cristiano Ronaldo', '2013/2014'); echo $query1; There will be several drop down lists, 2002/2003 > selecting this will create a variable called $season with the value " WHERE season=1" 2003/2004 > selecting this will create a variable called $season with the value " WHERE season=2" 2004/2005 > selecting this will create a variable called $season with the value " WHERE season=3" etc etc OR 2002 > selecting this will create a variable called $year with the value " WHERE year=2002" 2003 > selecting this will create a variable called $year with the value " WHERE year=2003" 2004 > selecting this will create a variable called $year with the value " WHERE year=2004" etc etc When I have selected any of the above form the form I will get another drop down list La Liga > selecting this will create a variable called $competition with the value " WHERE competition=La Liga" Champions League> selecting this will create a variable called $competition with the value " WHERE competition=Champions League" etc and finally another drop down list International > selecting this will create a variable called $level with the value " WHERE level=International" Domestic> selecting this will create a variable called $level with the value " WHERE level=Domestic" When the submit button is pressed that variable will pass through the query_create and echo out the relevant results. I don't know where to start on this as I am a total novice at this, could someone help me out with this?Also if there is someway I can do this with AJAX to refresh results without refreshing the page? Edited March 25, 2014 by AasimAzam Quote Link to comment https://forums.phpfreaks.com/topic/287247-using-drop-down-menus-to-update-mysql-results/ Share on other sites More sharing options...
Solution WebStyles Posted March 25, 2014 Solution Share Posted March 25, 2014 here's a very simple example of a dropdown that calls a javascript function (submitChange) every time something is selected. You would use that function to grab the dropdown value and create an ajax call to a php file. <!-- html form dropdown example --> <select name="year" onchange="submitChange()"> <option value="2002">2002</option> <option value="2003">2003</option> <option value="2004">2004</option> </select> <?php // page that ajax calls $year = trim($_POST['year']); $query = "select `something` from `something`"; if(!empty($year)){ $query .= " where `year` = '$year'"; } ?> Hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/287247-using-drop-down-menus-to-update-mysql-results/#findComment-1473810 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.