User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 360,994 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,543 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 2568 | Replies: 4
Reply
Join Date: Apr 2006
Posts: 5
Reputation: AdamW is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
AdamW AdamW is offline Offline
Newbie Poster

Search facility for a drop down box

  #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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,857
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Search facility for a drop down box

  #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.
Reply With Quote  
Join Date: Apr 2006
Posts: 5
Reputation: AdamW is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
AdamW AdamW is offline Offline
Newbie Poster

Re: Search facility for a drop down box

  #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  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,857
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 106
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: Search facility for a drop down box

  #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.
Reply With Quote  
Join Date: Apr 2006
Posts: 5
Reputation: AdamW is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
AdamW AdamW is offline Offline
Newbie Poster

Re: Search facility for a drop down box

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 6:32 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC