1

What would be the best way to create a filter feature in PHP so the user can select which records they want displayed in a table.

For example, a database of addresses. I want to add a feature so the user can select which county they want displayed in a table (A filter feature).

I plan to just run a for each to loop through each of the rows and add the county to a checkbox group so then the user can check which of the counties they want to be displayed then I can base my MySQL query on that but I figures it would take time especially since I'd be having 5000 or more records.

What would be the most convenient way to achieve this and is there a command or a feature in PHP to get all the unique values in a column so I can list them in the filter box?

1
  • the best way is with ajax (reload the page without redirection); and for get all unique values, you can use the requete sql "SELECT DISTINCT your_col FROM your_table" Commented Jun 7, 2016 at 9:55

1 Answer 1

1

Focus more on the SQL aspect of the problem. Try:

SELECT DISTINCT column_name FROM table_name;

Also, you could make your database such that the countries are foreign keys to another COUNTRY table. this will reduce a huge amount of redundancy as the database is not filled with repeated mentions of same names.

NOTE: Never retrieve all the entries from the database and run for each loops, try to retrieve as few rows as possible from the database.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, been away for a while. I will test this but it looks like it is what I'm looking for, wasn't aware there's a SELECT DISTINCT command :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.