Jump to content


Photo

trying to search the mysql database but it's not working


  • Please log in to reply
5 replies to this topic

#1 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 02 September 2006 - 01:52 PM

Hey what i'm trying to do is search the database using the value the user inputs in the search feild that is in PHP.

currently i'm taking the values from this input='text' feild (the user types in keywords) and connecting to the database and running



//$keywords contains the value form the search feild
$sql = "SELECT * FROM catalogue WHERE `keywords`='$keywords'";


now in the database, the user can upload up to 200 keywords to a each photo they upload, but for some odd reason, the keywords im testing with match in the database but no results are being returned???

is there a quicker mysql string i can use?

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 02 September 2006 - 03:51 PM

Try using LIKE with % wildcards.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 Craigypoos

Craigypoos
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 September 2006 - 09:15 PM

Try using LIKE with % wildcards.


How, exactly?

I've been having the same problem.  I have a database full of motorbike parts and I want to be able to search the entire database for a search string such as "clutch" to retrieve all the clutch related parts from my database (ie clutch levers, clutch cables, etc etc)...

I've tried various different variations using LIKE and % and just can't seem to get it to work.  I've even tried using MATCH....AGAINST, but to no avail.  Could you give an example of the code syntax?

Cheers,
Craigypoos




#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 05 September 2006 - 10:07 PM

Well, field LIKE '%clutch%' is definitely going to work... it's just a question of how efficient this is.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 Craigypoos

Craigypoos
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 05 September 2006 - 10:33 PM

Thanks for your reply.

However, I seem to have a MATCH AGAINST clause thing going on now, and it works lovely...

except, some of the words used to search for will be the names of bikes (such as CBR or GSXR) so the 4 letter lower limit kicks in.  It's late now, but I reckon tomorrow I'll try it the LIKE way or write a php IF thingy to choose whether to do the query IN BOOLEAN MODE or not....

Thanks anyway for your (very prompt) help.

Craigypoos




#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 September 2006 - 01:32 PM

Or you can roll-your-own index column.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users