DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   Search facility for a drop down box (http://www.daniweb.com/forums/thread42695.html)

AdamW Apr 5th, 2006 5:01 am
Search facility for a drop down box
 
Hi I'm new here so be gentle! ;)

I have a php form which poppulates an HTML <Select> tag with a list of approx 2500 items which consist of an id; a code and a name. The items come from a MySql database

To make it easier to use I want to be able to optionally limit the number of lines to select from based on a search criteria.

What is the best way of going about this please?

cscgal Apr 5th, 2006 11:05 am
Re: Search facility for a drop down box
 
You would simply use the WHERE and LIMIT clauses in your MySQL select statement. For example,

SELECT * from mytable; selects all rows from a table named mytable.
SELECT col1, col2 from mytable; selects only the columns entitled col1 and col2 from mytable.
SELECT col1, col2 from mytable WHERE col1 = 1; selects only the columns entitled col1 and col2 from records where col1 is the value 1.
SELECT col1, col2 from mytable WHERE col1 = 1 LIMIT 10; does the same as the previous line only selects just the first ten records it finds, regardless of how many fulfill the WHERE criteria.

AdamW Apr 5th, 2006 11:21 am
Re: Search facility for a drop down box
 
I need to be able to limit to a search criteria which I wont know until after the page is displayed. I can not construct the where part of the sql at the time I first need the records so I need to be able to search within the record set on the page itself in order to populate the $_Post with the record id.

Does that make sense?

cscgal Apr 12th, 2006 1:12 pm
Re: Search facility for a drop down box
 
After you retrieve a MySQL resource array, one usually loops through it to output it. Within that loop, simply use an IF clause, and only output if a particular condition is true.

AdamW Apr 13th, 2006 4:43 am
Re: Search facility for a drop down box
 
Thanks, I ended up by using a nice little Java Script function which can be found here to filter the options

Adam


All times are GMT -4. The time now is 8:35 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC