Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 5
Joined: Sun Jan 12, 2020 11:29 pm

Sun Jan 12, 2020 11:42 pm

Hi everyone.
I have a database that I would like the user to be able to filter using a drop down which will then take the user to a new page with the filtered parameters carried on the URL. Example:

Database contains 3 columns (Spain, France, Germany), rows are cities such as:
For Spain: Madrid, Barcelona
For France: Paris, Marseille
For German: Berlin, Koln

I would like that when the user picks using a drop-down: Spain and France, they will be taken to a URL such as:
in that link they will see only France and Spain and their city in a table.
So total will be 3 elements: (mysql database, page1 with drop down list, page2 with table with the filtered data).
Can anyone help with this? Thank you so much!!!
php-forum GURU
php-forum GURU
Posts: 653
Joined: Fri Apr 01, 2016 2:18 am

Mon Jan 13, 2020 5:25 am

You get URL parameters via the varialbe $_GET. But only unique keys are allowed, or you use an array like ?country[]=france&country[]=spain. After checking all array items against a whitelist, using array_filter() and in_array() or array_intersect(), you can turn them into a comma seperated list to use within the IN statement in your database query.
Post Reply