Hello php community,

Could you help me in my research? I just cannot find what I am looking for.

I am working on a website with PHP and MySQL.
I am trying to get a filter option on my website to fetch the information from database.
Here are the filter options:
-Team 1
-Team 2
-Team 3
-Team 4

I'm trying to impliment a filter, by pressing it, show specific data from database in my html table.

If yuou know of a website/tutorial that can help me please let me know.


Ok sounds like your tables may not be normalized properly - apologies if this is not your case. For example, your teams should be given a unique identifier or id (Primary Key) in their own table. Any reference to teams outside your teams table, must not be on the id field (BTW this field can be called anything you like, but id is the convention). For example, a soccer results table...

id | gamedate | team_1 | team_2 | score_1 | score_2 (where team_1 denotes the home team and team_2 denotes the away team, score_1 and score_2 , the number of goals each team scores, respectively).

1 | 2018-09-08 | 7   | 86 | 3 | 1
2 | 2018-09-08 | 1   | 9 | 1 | 1
3 | 2018-09-08 | 6   | 22 | 0 | 1
4 | 2018-09-08 | 45   | 5 | 0 | 0
5 | 2018-09-08 | 61   | 54 | 5 | 3

So implementing a filter in html, is now just a question of, for example, providing the id of the team in the <option> tag value`:

<select name="team_filter">
    <option value="7">Cardiff City</option>
    <option value="45">Brynamman Eagles</option>
    <option value="23">Swansea City</option>
    <option value="16">Newport AFC</option>

You can produce this select field easily with a php loop with data from the DB. The ID of the team in question can be sent to the server (form or link and picked up with something like $_GET['team_filter']). This can be done via bog-standard form or Ajax; or you can even download all the data into js (e.g. json) and use js to hide/show the teams.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.