Jump to content

Using Drop Down Menus to update MYSQL results


Go to solution Solved by WebStyles,

Recommended Posts

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 by AasimAzam
  • Solution
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.