944,161 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 3994
  • MySQL RSS
Apr 5th, 2006
0

Search facility for a drop down box

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AdamW is offline Offline
5 posts
since Apr 2006
Apr 5th, 2006
0

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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002
Apr 5th, 2006
0

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AdamW is offline Offline
5 posts
since Apr 2006
Apr 12th, 2006
0

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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 163
The Queen of DaniWeb
cscgal is offline Offline
13,646 posts
since Feb 2002
Apr 13th, 2006
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AdamW is offline Offline
5 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Dynamic Next/Prev Buttons in PHP/MySQL
Next Thread in MySQL Forum Timeline: use of mysql unsigned ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC