Search facility for a drop down box

Reply

Join Date: Apr 2006
Posts: 5
Reputation: AdamW is an unknown quantity at this point 
Solved Threads: 0
AdamW AdamW is offline Offline
Newbie Poster

Search facility for a drop down box

 
0
  #1
Apr 5th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,026
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 125
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Search facility for a drop down box

 
0
  #2
Apr 5th, 2006
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.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5
Reputation: AdamW is an unknown quantity at this point 
Solved Threads: 0
AdamW AdamW is offline Offline
Newbie Poster

Re: Search facility for a drop down box

 
0
  #3
Apr 5th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,026
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 125
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Search facility for a drop down box

 
0
  #4
Apr 12th, 2006
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.
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5
Reputation: AdamW is an unknown quantity at this point 
Solved Threads: 0
AdamW AdamW is offline Offline
Newbie Poster

Re: Search facility for a drop down box

 
0
  #5
Apr 13th, 2006
Thanks, I ended up by using a nice little Java Script function which can be found here to filter the options

Adam
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC