tags:

views:

55

answers:

3

Hi again...

SELECT * FROM db WHERE description LIKE '$string' OR headline LIKE '$string'

My problem is that the $string variable must be exactly the same as one of the fields in order to work... But I want just a part of the field to be the same as the $string...

How can I do this?

Thanks again...

+4  A: 

Use %

SELECT * FROM db WHERE description LIKE '%$string%' OR headline LIKE '%$string%'
devpl
A: 

TRY

$query="SELECT * FROM db WHERE description LIKE '%".$string."%' OR headline LIKE '%".$string."%'";
halocursed
A: 

For the like statement, you must use the % character as a wildcard character. So if you wan all descriptions starting with foobar, you would use

SELECT * FROM db WHERE description LIKE 'foobar%' OR headline LIKE 'foobar%'

If you want all descriptions containing foobar, you would use

SELECT * FROM db WHERE description LIKE '%foobar%' OR headline LIKE '%foobar%'

Be careful when using %foobar% as it's usually very inefficient, especially if you have a lot of records. Because the text could be anywhere in the string, the database engine is unable to use indexes. If you have a lot of data, you may want to consider using fulltext indexing.

Kibbee