Best way for user to sort results

I am making a site so users can track their golf game.

I currently use this query to display all data. In the courses table.

<?php
			$result = mysql_query("SELECT * FROM courses ORDER BY coursename ASC");
			while ($row=mysql_fetch_array($result)) {
			echo "<a href='course.php?C=".$row['id']."'>".$row['courseName']."<a/><br />";}
					
					?>

The table has 16 columns, the only columns I want to work with is state then city.
I want to make it so that a user selects a state from a dropdown list, after selecting the state I want another dropdown list with the cities of that state, after selecting the city I want to display all the “courseName”'s that fall under that city and state. I also want to make a option to choose all cities in the state. I have been working on a way to do this with 3 different pages but I would like to make if all on one page. Any help is appreciated.

The traditional and less user-friendly way is to put up a form with just the states, when submitted a second page displays all the cities in that state and finally a third page displays all the golf courses.

I want to make it so that a user selects a state from a dropdown list, after selecting the state I want another dropdown list with the cities of that state,

That is often termed a “linked drop list” or “linked select boxes” or “linked drop down menu php”

Searching for those terms will turn up a way of achieving this on the client. Essentially, PHP creates the full array of states and cities, turns them into JS arrays and sends the lot to the client - heavy, but once loaded the sorting is instantaneous.

Another way to do this is to use Ajax to refresh parts of the page.

Which you choose may depend on;

a) your skills
b) whether you want your site to work with JS turned off
c) how many states/cities/golf courses you have

I presume this is what you were asking about rather than how to build up the sql statements …