Jump to content

mysql query problem


ukscotth

Recommended Posts

Hi all,

 

Anyone know why this query is giving me the wrong results ?

 


$books2 = mysql_query("SELECT * FROM books WHERE (extra1 LIKE '%$cat%') OR (extra2 LIKE '%$cat%') OR (extra3 LIKE '%$cat%') AND type = 'public'");

 

Its giving me results that dont have the 'type' 'public'

 

Any ideas ?

 

Many thanks in advance.

 

Scott

Link to comment
https://forums.phpfreaks.com/topic/244912-mysql-query-problem/
Share on other sites

change to:

 

$books2 = mysql_query("SELECT * FROM books WHERE (extra1 LIKE '%" . $cat. "%'") OR (extra2 LIKE '%" . $cat. "%'") OR (extra3 LIKE '%" . $cat. "%'") AND type = public");

concatenation is not needed..

 

not an expert in SQL, however perhaps you should try encasing you or statements inside of parenthesis..

 

$books2 = mysql_query("SELECT * FROM books WHERE ((extra1 LIKE '%$cat%') OR (extra2 LIKE '%$cat%') OR (extra3 LIKE '%$cat%')) AND type = 'public'");

 

Link to comment
https://forums.phpfreaks.com/topic/244912-mysql-query-problem/#findComment-1258077
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.