Forum Moderators: coopster

Message Too Old, No Replies

Simple Wild card search script for phpbb site

         

columbus

9:31 pm on Mar 18, 2006 (gmt 0)

10+ Year Member



Is there a way to to impliment automatic wild card searches.

Example someone types in the zip code 90210 in the search screen.

Its automatically changed to 902*

Yielding the results

90210
90213
90245
. . . . and so on

coopster

1:30 pm on Mar 19, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure. If the data is coming from a database all you have to do is modify the search query to add a LIKE keyword:
SELECT zip_code FROM mytable WHERE zipcode LIKE '902%';

columbus

5:14 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



I dont think I can use a sql string here.

This is for a phpbb search on my site for the users of the forum . . . not me. I think I can accomplish this task by using a "form" but not sure how to write it.

If I can use sql how do i do this?

coopster

5:33 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Sure you can. As a matter of fact, that is what I thought you were describing in your first message. In a nutshell, you would:
  1. Create the HMTL form which accepts user input.
  2. Edit the input to make sure it contains digits; keep the first three digits, discard the rest. Use that to build your query statement.
  3. Execute the query statement, process the result set and display the information.

And welcome to WebmasterWorld, by the way ;)