Page 1 of 1

search using drop down boxes

Posted: Thu Feb 07, 2008 2:21 pm
by synchro
hey guys
im looking to have a search function in my website that will allow the user to filter down his/her search using the drop down boxes.
I don't know wher to even start with this one, has anyone got any code, that might work?
thanks very much
Dave

Re: search using drop down boxes

Posted: Thu Feb 07, 2008 3:30 pm
by RobertGonzalez
Hi there. Generally speaking no one here will give you code. We will help you with what you have already done, and point you in the right direction if you have no idea where to start.

What have you tried so far?

Re: search using drop down boxes

Posted: Fri Feb 08, 2008 2:28 am
by synchro
to be honest i have no idea where to start
im tryiing to create a page on my website where i have a number of drop down boxes, for :
location
car type
fuel type
price range

i want all the options for these categories to be sourced from my database.
so that when u click ontheach drop down box, u can select your choice.
i then just want a 'search' button, at the end of the webpage, which will bring u to the results page.
any help would be gratly appreciated.
thanks very much,
Dave

Re: search using drop down boxes

Posted: Fri Feb 08, 2008 10:23 am
by RobertGonzalez
Sweet, so you are moving into the earliest of "Database driven web application development with PHP". That is awesome.

Here is a short rundown of how you could go about this.

1) Set up your database and related tables
2) Populate your tables with some test data
3) Write a PHP script that interfaces with the database, selects everything from the tables and builds the drop down with the data
4) Use the dropdown (select) items (option value) as the search parameter. Since it is a form it will be a $_POST array value
5) Use the $_POST array values to interface with the database again, this time passing the values to a different select query

If you haven't already I'd suggest downloading the sample chapters of Kevin Yank's book Build Your Own Database Driven Website Using PHP & MySQL. It goes into very basic detail all of the things that I just suggested above. If things get to overwhelming for you when following the samples, hit us up.

I suggest this to almost all new PHP coders. It is what I learned from originally. That, and this community.

Good luck.

Re: search using drop down boxes

Posted: Fri Feb 08, 2008 12:40 pm
by califdon
Good advice to a beginner, Everah! It is indeed hard to know where to start.