Forum Moderators: coopster

Message Too Old, No Replies

Searching Several Columns in MYSQL

Searching multiple columns on the same spreadsheet

         

curlykarl

3:09 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



Hi

I wonder if anyone can point me in the right direction on this, I am trying to search multiple columns on a single database and display the info.

I have this set up but it only queries one.

$query_rsSearch = sprintf("SELECT * FROM database WHERE column1 LIKE '%%%s%%'", $colname_rsSearch);

The above works fine for one column but I am having difficulty making it search more than one, I have been trying this method.

$query_rsSearch = sprintf("SELECT * FROM database WHERE column1,column2 LIKE '%%%s%%'", $colname_rsSearch);

But continually get error messages?

Any pointers would be appreciated.

Thank you

Karl :)

HelenDev

3:21 pm on Jun 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about


SELECT * FROM database WHERE column1 LIKE '%%%s%%' OR column2 LIKE '%%%s%%' OR column3 LIKE '%%%s%%'

curlykarl

3:38 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



Thanks Helen,

I think I'm getting closer :)

I no longer get the error message, I now get 'Query was empty'

I'm still at the PHP/MYSQL pre-school level :)

Karl

curlykarl

3:49 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



Helen

Thank you for your help :)

I just added

$colname_rsSearch,$colname_rsSearch);

at the end of what you suggested, and it works!

Karl :)