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

Link to comment
Share on other sites

:) :)

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
Share on other sites

  • 3 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.