On my website I have a dropdown of counties…
<form method="post" action="/people.php" >
<select name="county" onchange="this.form.submit()" >
<option>--Select a County--</option>
<option value="Avon">Avon</option>
<option value="Bedfordshire">Bedfordshire</option>
<option value="Berkshire">Berkshire</option>
</select>
</form>
I then have my query on my people page…
$county = $_POST['county'];
$sth = $conn->prepare("SELECT * FROM directory WHERE user_active != '' AND County = :county");
$sth->execute(array(':county' => $county));
I want to use URL rewrites to include the county in my url, so when you go to the page after selecting a county it doesnt display like
'www.mysite.com/people.php'
but shows as
'www.mysite.com/people-in-avon'
Im still very much a newbie at PHP but, if I want to do this, will I need to use GET method, and post my data to a php page, that then redirects to people.php? Is it bad practice in PHP to have the queries on page?
I hope this makes sense?
You first need to use an .htaccess with some basic redirections to be able to use people-in-[country] URLs.
In your people.php :
To create the URL, you should replace special characters, accents, space…
But if your counties are in one word, without special characters, you could just do :
To retrieve by ID your county, you could do something like that (pseudo code):
To show the county :
To route to the county :