View Full Version : Creating a "filter"

17 Feb 2010, 04:23 PM
Hi All,

This is my first post here so I'll do a quick intro:

I am currently in school talking Website Development, and am moderately proficient with CSS, XHTML, and Photoshop. I'm going to be taking Javascript, Flash, and PHP in the near future.

Alright, so here's my question:

I'm currently looking to build a website that will require me to be able to use a search filter. For example: If I were creating a website that had movie reviews, I'd like the user to have the ability to filter the reviews by genre, release year, actors, etc. I'd also like them to be able to organize results (for example, having newest releases first). It's more important that I have a simple filter, but a standard keyword search-box would be nice too. What platform/language would I need to use to get that done, and do you know of any resources (like a good tutorial) that will teach me how to do that?

I'm guessing it's PHP but am not sure, and would like to get started on this project asap.

Any suggestions or help you can give would be great. Thanks!

07 Mar 2010, 08:37 PM
Yep you will need knowledge of PHP and MySQL (or another other database, but if I create an example it will be with MySQL).

Before I start, the records i am using in the database are wrong, I don't know the date so i just made one up. And I am very tired, so if i make a mistake I will correct it next time I'm on. Also i will post links at the end of this thread.

You would create a database, called eg:

Database Name: film_website
Database Table: reviews

| id | film_name | film_genre | release_date |
| 1 | James Bond: Gold finger | Action | 1992 |
| 2 | The Sound Of Music | Music | 1987 |
| 3 | James Bond: Octopussy | Action | 1994 |
| 4 | Die Hard 2 | Action | 1998 |

Now you have records in your table, you can manipulate the data using PHP. Just skipping a big shunk of information here, but what you can do is this:

You can basically write a PHP/MySQL script that says:

SQL: SELECT * FROM reviews WHERE film_genre = "Action"
English: SELECT all of the data FROM reviews table WHERE film_genre = "Action"

This will select row, 1,3,4 from the database.

When you extract the data you can sort the data by any column in the database, eg the "film_genre" column, or the "release_date" column. You do this by adding to this SQL command:

SQL: SELECT * FROM reviews WHERE film_genre = "Action" ORDER BY release_date DESC

Official MySQL Wesbite: http://dev.mysql.com/
MySQL tutorials: http://www.tizag.com/mysqlTutorial/

You will also need to familiarize yourself with PHP (http://www.php.net/)

Let me know how your finding this, its the first tutorials based post i have ever written, so I don't know how understandable your going to find it.