Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple keywords search problem

Status
Not open for further replies.

queryguy

Programmer
Oct 10, 2003
23
SG
$terms = explode(" ", $_GET["items"]);
$query = "SELECT * FROM warehouse WHERE";
$numterms = count($terms);
for($b = 0; $b < $numterms; $b++) {
$terms[$b] = trim($terms[$b]);
if($b > 0) {
$query .= &quot; OR&quot;;
}
$query .= &quot; items LIKE '%&quot; . $terms[$b] . &quot;%'&quot;;
$query .= &quot; and listid LIKE '%&quot; . $listid . &quot;%'&quot;;
$query .=&quot; and listed LIKE '1'&quot;;
$query .=&quot; order by active desc, listed desc&quot;;
$results=mysql_query($query) ;

}


This code is for searching my database with multiple keywords, but it only can enter one key word at a time for searching, if enter 2 keywords it will return no results. Anyone here can tell me how to solve this problem?
 
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR items LIKE '%%' and listid LIKE '%1%' and listed LIKE '1

this is all it displayed
 
this error will only occurs when I entered 2 keywords to search, with one keyword, it display results without problems.
 
Tip:
print the entire SQL statement that is created. First with 1 term, then with more. Let's see the output.
(I suspect your OR structure is malformed. It should be in parenthesis etc.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top