GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   MySQL gurus in here now please. (https://gfy.com/showthread.php?t=709476)

Nookster 02-25-2007 01:15 PM

MySQL gurus in here now please.
 
So I've been trying to get a damn search option to work with one of my mainstream projects for the past day or so but it's just not working. Here's the query I'm using:
Quote:

$trysrch = @mysql_query("select * from table_name where item_name like '$srch' || item_name2 like '$srch' || item_name3 like '$srch' && area = '$place' order by item_name asc");
Looks fine right? According to documentation this should work. Well, all of the selects for the OR (||) work, but once it gets to the AND part it seems to just overlook it and doesn't do anything. It does finish successfully (as in no errors) but it doesn't use the AND part (doesn't further narrow the results by executing the actual logic).
My questions: Why doesn't this work? What am I doing wrong if it's wrong?
This has been frustrating the shit out of me. :disgust
Thanks to all who will be kind enough to reply.

tical 02-25-2007 01:17 PM

put the OR parts in parenthesis, i think that should fix it

$trysrch = @mysql_query("select * from table_name where (item_name like '$srch' || item_name2 like '$srch' || item_name3 like '$srch') && area = '$place' order by item_name asc");

WarChild 02-25-2007 01:18 PM

You don't understand how "OR" works. Read more grasshopper, read more. :)

WarChild 02-25-2007 01:21 PM

I believe your statement is being evaluated like this:

item_name like '$srch'
OR
item_name2 like '$srch'
OR
item_name3 like '$srch' AND area = '$place' order by item_name asc

Nookster 02-25-2007 01:27 PM

Quote:

Originally Posted by tical (Post 11972064)
put the OR parts in parenthesis, i think that should fix it

$trysrch = @mysql_query("select * from table_name where (item_name like '$srch' || item_name2 like '$srch' || item_name3 like '$srch') && area = '$place' order by item_name asc");

Thank you very much. It works great now. :thumbsup Guess I should read more. :1orglaugh

BT 02-25-2007 01:28 PM

go fuck your self


All times are GMT -7. The time now is 09:52 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc