Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Search function within dreamweaver / SQL

New Here ,
Jul 11, 2009 Jul 11, 2009

Hi, I've been a couple of simple shopping sites through Dreamweaver.

One feature all products - www.drinkemporium.com - the other just a selection of products (one kind) - www.vodkaemporium.com.

At the moment, the two sites use separate databases, with the vodka stuff duplicated in its own db. I'd like to combine both sites to use a single db.

However, I've hit a problem. Both sites use a simple search engine. How do I set the vodka site to only search the vodka products in my db? Product types are set by an entered value in one of the db columns.

My SQL code looks like this:

SELECT *
FROM drinkemporium
WHERE Name LIKE CONCAT('%', colname, '%') OR Description LIKE CONCAT('%', colname2, '%')

I need to add another criteria telling it to only search results where Type = X and not Y or Z.

Can anyone help?

TOPICS
Server side applications
706
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2009 Jul 11, 2009

>I need to add another criteria telling it to only search results where Type = X and not Y or Z.

Your where clause needs to look something like this

WHERE (Name LIKE CONCAT('%', colname, '%') OR Description LIKE CONCAT('%', colname2, '%')) AND Type= 'vodka'

Make sure you wrapp the OR'ed expressions with parens so they are evaluated together, and the AND'd expression is evaluated separately.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2009 Jul 12, 2009
LATEST

Brilliant thanks!

I had to put the Type query at the start... but it now works.

SELECT *
FROM drinkemporium
WHERE Type=vodka AND (Name LIKE CONCAT('%', colname, '%') OR Description LIKE CONCAT('%', colname2, '%'))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines