Jump to content

Archived

This topic is now archived and is closed to further replies.

leeroy1

search multiple fields

Recommended Posts

I have a contacts table with name, address, tel number, fax number, etc. How would I setup a search page with only one text box that would return results for any field searched on? ie. user enters a telephone number, results page would show any record that had that same telephone number. user2 enters an address in same text search box, results page shows records with matching address.

 

I guess my real question is how to setup a single entry that will span across multiple fields when it does it's search.

Share this post


Link to post
Share on other sites

$result = mysql_query ("select * from TABLE where FIELDNAME like '%$txtsearch%' order by FIELDNAME");
($row = mysql_fetch_array($result))

 

The [*] pulls all fields from that table.

 

If you wished to see only one field replace then [*] with [FIELDNAME]

 

Multi fields [FIELDNAME1, FIELDNAME2]

 

then to pull the field data

 

print ("<TD>");
print $row["FIELDNAME"];
print ("</TD>");

Share this post


Link to post
Share on other sites

Close to what I was asking about but not quite.

 

What I meant was...I want to have a single text search box. In this box users will be able to type in any client contact info they want(it will be based on a client contact table). They could type in "3333333333" for a phone number or type in "Billy Bob" or type in "33 Test Rd". From their input the search would look at all fields in the table and return anything that matched. It wouldn't search for a match only on one field. Is this possible? Would it bog down the server on 10 thousand records, 250,000 records?

Share this post


Link to post
Share on other sites

I got it going. Just created a sql statement for the record set results to find %fieldname% for each field name and pointed to the posted text entry.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.