budimir Posted October 8, 2013 Share Posted October 8, 2013 Guys, Can someone explain me, why this query is failing: $upit_prikaz = "SELECT * FROM katalog_pribora_item LEFT JOIN katalog_pribora_slike ON katalog_pribora_item.id = katalog_pribora_slike.id_item WHERE (grupa_artikla = '1HP' OR grupa_artikla = '1HU') AND novi_pribor = '1' AND prikaz_katalog = '1' "; $query_prikaz = mysql_query($upit_prikaz) or die (mysql_error()); And this one is working fine: $upit_prikaz = "SELECT * FROM katalog_pribora_item LEFT JOIN katalog_pribora_slike ON katalog_pribora_item.id = katalog_pribora_slike.id_item WHERE grupa_artikla = '1HP' AND novi_pribor = '1' AND prikaz_katalog = '1' "; $query_prikaz = mysql_query($upit_prikaz) or die (mysql_error()); Difference is that lower one is not having one OR statment. Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/ Share on other sites More sharing options...
mac_gyver Posted October 8, 2013 Share Posted October 8, 2013 define: this query is failing? what result is it producing and what is wrong with that result? Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453105 Share on other sites More sharing options...
Solution B_CooperA Posted October 8, 2013 Solution Share Posted October 8, 2013 Have you tried to execute that query in PHPMyAdmin or similiar? Does it gives you a syntax error or just not working? What I would suggest is that you remove the parenthesis outside the OR statement. Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453123 Share on other sites More sharing options...
Barand Posted October 8, 2013 Share Posted October 8, 2013 with the parentheses you have (A OR B) AND C AND D without, you will effectively have A OR (B AND C AND D) Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453173 Share on other sites More sharing options...
vinny42 Posted October 9, 2013 Share Posted October 9, 2013 without, you will effectively have There is no OR in the second query. :-) However, the first query will also grab records with grupa_artikla = '1HU', the second only '1HP', so my guess is there are no records that have '1HP' that meet the other requirements. Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453219 Share on other sites More sharing options...
Barand Posted October 9, 2013 Share Posted October 9, 2013 There is no OR in the second query. :-) I was referring to the first query and it was a caveat if following B_CooperA's suggestion Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453256 Share on other sites More sharing options...
vinny42 Posted October 9, 2013 Share Posted October 9, 2013 I was referring to the first query and it was a caveat if following B_CooperA's suggestion I clearly wasn't awake yet, sorry :-) Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453259 Share on other sites More sharing options...
budimir Posted October 9, 2013 Author Share Posted October 9, 2013 Guys, I have managed to track my problem. Query is actually working as it was suposed to, but I messed up with id linking. That's why it couldn't return any data. Got it all sorted out now. Thank you for you're help. B_CooperA pushed me to a good track. Quote Link to comment https://forums.phpfreaks.com/topic/282813-mysql-search-query-failing/#findComment-1453313 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.