Jump to content

Searching multiple field of one table


Peggy

Recommended Posts

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

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.

:) :)

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!!!!

  • 3 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.