Search in DB Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
alsaffar
Forum Newbie
Posts: 16
Joined: Sun Sep 29, 2002 12:03 pm

Search in DB Problem

Post by alsaffar »

Hi there,

I have a problem regarding searching for keywords from a field in a table in MySQL.

In a.php page:

<form method="post" action="b.php">
<input name="Keywords">
</form>

In b.php page:

$Query = " SELECT * FROM TableName WHERE FieldName like '%$_POST[Keywords]%' ";

This will works only if the user wrote 1 word and that word is exactly in that field, BUT what I want is:

to add another inputs to the form:

<input type="radio" name="SearchMethod" value="AllWords">
<input type="radio" name="SearchMethod" value="AnyWord">

So if the user choused "AllWords", the query should returns the records that only have all words and not nesesary same order and not same letter case. (i.e. the user searched for "Toyota Supra" and in DB is "supra toyota")

And if he choused "AnyWord", how can I test each word in the "Keywords" input?

I hope I was clear :rolleyes:
Post Reply