Peggy Posted January 19, 2010 Share Posted January 19, 2010 I'm trying to search more than one field of only one table of a data base. I've tried a lot of different variations but none of them seem to work. The first code below will work for searching only one field. $query = "SELECT * from products WHERE fulldescr like \"%$trimmed%\" order by product ASC"; -------------------------------------------------------------------------------------------------------------- Here are some of the variations that didn't work for searching multiple fields $query = "SELECT fulldescr, product, descr, keywords FROM products WHERE fulldescr LIKE '\"%$trimmed%\"' OR product LIKE '\"%$trimmed%\"' OR descr LIKE '\"%$trimmed%\"' OR keywords LIKE '\"%$trimmed%\"' order by product ASC"; $query = "SELECT fulldescr, product, descr, keywords FROM products MATCH (fulldescr, product, descr, keywords) AGAINST (\"%$trimmed%\")"; //---------------------------------------------------------------------- I Really appreciate any help!! Link to comment https://forums.phpfreaks.com/topic/189093-searching-multiple-field-of-one-table/ Share on other sites More sharing options...
schilly Posted January 20, 2010 Share Posted January 20, 2010 It looks like your search query is double quoted: '\"$trimmed\"' Try $query = "SELECT fulldescr, product, descr, keywords FROM products WHERE fulldescr LIKE '%$trimmed%' OR product LIKE '%$trimmed%' OR descr LIKE '%$trimmed%' OR keywords LIKE '%$trimmed%' order by product ASC"; Also make sure you output the mysql error which should help you as well. Link to comment https://forums.phpfreaks.com/topic/189093-searching-multiple-field-of-one-table/#findComment-998365 Share on other sites More sharing options...
Peggy Posted January 20, 2010 Author Share Posted January 20, 2010 :) Thank You!!!! I knew it had to be a simple answer. I just hadn't figured it out. This is actually the code I ended up using. $query = "SELECT * from products WHERE fulldescr like \"%$trimmed%\" OR product like \"%$trimmed%\" OR descr like \"%$trimmed%\" OR keywords like \"%$trimmed%\" order by product ASC"; Thanks Again!!!! Link to comment https://forums.phpfreaks.com/topic/189093-searching-multiple-field-of-one-table/#findComment-998795 Share on other sites More sharing options...
pbucc Posted May 11, 2010 Share Posted May 11, 2010 so did this work for you? i am working something similar. Link to comment https://forums.phpfreaks.com/topic/189093-searching-multiple-field-of-one-table/#findComment-1056570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.