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

Advanced Search Results PHP

Contributor ,
Dec 31, 2012 Dec 31, 2012

Copy link to clipboard

Copied

Hello, I am designing my first Dynamic Website in PHP and WAMP and have so far managed to create a working Search Element on my website (search for 20mm on www.reese-test.co.uk )

It shows a linkable pic in "column 1" and Description in "column 2".

What I would ideally like though is to seperate the code and description columns (as shown below - pic 1), the problem is the search only works by finding the content in the description column, I have tried all different things in the "Advanced" tab to Filter by "Code" and "Description" but it is still only filtering by "Description" only.

simpleRS.jpg advancedRS.jpg

My question is, does anyone have any simple instructions to get it to filter for both columns. In the "Simple" panel I can only select one option to filter!!!

thankyou for your help!

TOPICS
Server side applications

Views

1.2K
Translate

Report

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

correct answers 1 Correct answer

LEGEND , Dec 31, 2012 Dec 31, 2012

>I have tried all different things in the "Advanced" tab to Filter by "Code" and "Description"

To write SQL queries you need to understand Boolean logic. You can't use AND  because that would mean that both conditions would need to be true. You want results if either condition is true, so use OR.

Select *

FROM productlist

WHERE description LIKE %colname%

OR

code LIKE %colname%

ORDER BY code ASC

Votes

Translate
LEGEND ,
Dec 31, 2012 Dec 31, 2012

Copy link to clipboard

Copied

>I have tried all different things in the "Advanced" tab to Filter by "Code" and "Description"

To write SQL queries you need to understand Boolean logic. You can't use AND  because that would mean that both conditions would need to be true. You want results if either condition is true, so use OR.

Select *

FROM productlist

WHERE description LIKE %colname%

OR

code LIKE %colname%

ORDER BY code ASC

Votes

Translate

Report

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
Guru ,
Jan 01, 2013 Jan 01, 2013

Copy link to clipboard

Copied

. . .also, LIKE is a rinkydink search method. Better to use MATCH. . .AGAINST.

http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html

Votes

Translate

Report

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
Contributor ,
Jan 02, 2013 Jan 02, 2013

Copy link to clipboard

Copied

LATEST

thankyou BREGENT. that worked although to get it working, I had to lay it out like:

SELECT *

FROM productslist

WHERE `description` LIKE %colname% OR `code` LIKE %colname%

ORDER BY code ASC

Rob: I cant see what i should change, do you mean something like: (appologies - first time i've done this!)

SELECT * MATCH `description` AGAINST `code`

FROM productslist

WHERE `description` LIKE %colname% OR `code` LIKE %colname%

ORDER BY code ASC

Votes

Translate

Report

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