iwpg Posted March 30, 2009 Share Posted March 30, 2009 This is killing me. I know it should be simple, but I cannot get the statement to run. $q = mysql_query("select * from db where item1 like '%$keyword%' or item2 like '%$keyword%' or item3 like '%$keyword%'"); Basically, the query is checking table 1,2 and 3 for the keyword, and returns the result if found. Any help will be greatly remembered and appreciated. Thanks, Mike Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/ Share on other sites More sharing options...
kickstart Posted March 30, 2009 Share Posted March 30, 2009 Hi Are you checking against several different tables? If so then $q = mysql_query("select * from table1 where item1 like '%$keyword%' UNION select * from table2 where item2 like '%$keyword%' UNION select * from table3 where item3 like '%$keyword%'"); All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-796731 Share on other sites More sharing options...
iwpg Posted March 30, 2009 Author Share Posted March 30, 2009 I'm really sorry. It's the same table, but checking in different columns. Thanks, and sorry for the confusion. Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797305 Share on other sites More sharing options...
revraz Posted March 30, 2009 Share Posted March 30, 2009 What do you mean you can't get it to run? Do you get an error? Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797337 Share on other sites More sharing options...
iwpg Posted March 30, 2009 Author Share Posted March 30, 2009 I get a blank result (Warning: mysql_result(): supplied argument is not a valid MySQL result resource) Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797351 Share on other sites More sharing options...
revraz Posted March 30, 2009 Share Posted March 30, 2009 Use mysql_error() after your querry to see if an error is returned. Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797362 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Use mysql_error() after your querry to see if an error is returned. That, and post your current relative code. Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797365 Share on other sites More sharing options...
grissom Posted March 31, 2009 Share Posted March 31, 2009 Hi iwpg Nothing immediately strikes me as wrong but in situations like this I try throwing in a few more brackets into the expression just to make it more explicit $q = mysql_query("select * from db where (item1 like '%$keyword%') or (item2 like '%$keyword%') or (item3 like '%$keyword%') "); The brackets may be surplus to requirements but I'd always rather have some surplus ones than not enough. Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797808 Share on other sites More sharing options...
iwpg Posted March 31, 2009 Author Share Posted March 31, 2009 Thanks for the help everyone, it should have been: $q = mysql_query("select * from db where (item1 like '%$keyword%' or item2 like '%$keyword%' or item3 like '%$keyword%')"); Quote Link to comment https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/#findComment-797907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.