Jump to content


Photo

Search filter


  • Please log in to reply
2 replies to this topic

#1 jerastraub

jerastraub
  • Members
  • PipPipPip
  • Advanced Member
  • 77 posts

Posted 17 October 2006 - 11:12 PM

I am using the following select statement:

$result = mysql_query("SELECT count(*) from sierratrdingpost_items WHERE PrimaryDepartmentID = '154' AND prodSku LIKE '%$search%' || prodName LIKE '%$search%' || prodDesc LIKE '%$search%' || prodBrand LIKE '%$search%' || UniqueprodSku LIKE '%$search%' || prodPrimCat LIKE '%$search%' || prodSecCat LIKE '%$search%'");

For some reason it isn't recognizing the

PrimaryDepartmentID = '154'

in this statement. As I am running a database that has mens, women's and childrens clothing.

However for this site search I just want to pull the men's clothing which has a PrimaryDepartmentID of 154.

Can you tell me what i am missing here, I have messed with it and just can't get it to work right.

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 17 October 2006 - 11:16 PM

you've got to put parenthesis around the groupings in your where clause to tell SQL what presidence you want it to take:
SELECT count(*) from sierratrdingpost_items WHERE PrimaryDepartmentID = '154' AND (prodSku LIKE '%$search%' || prodName LIKE '%$search%' || prodDesc LIKE '%$search%' || prodBrand LIKE '%$search%' || UniqueprodSku LIKE '%$search%' || prodPrimCat LIKE '%$search%' || prodSecCat LIKE '%$search%')

notice the parenthesis around all the sku checks. this will assure that ONE of the OR clauses is true, but the AND is always required.

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 jerastraub

jerastraub
  • Members
  • PipPipPip
  • Advanced Member
  • 77 posts

Posted 17 October 2006 - 11:25 PM

Tks, that works perfect!!!1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users