Rommeo Posted December 22, 2011 Share Posted December 22, 2011 For the website I m working on one table is like : table_user usernaname | shoppingbox rommeo | 1 3 5 19 36 89...94 105 1002 julliet | 3 5 6 8 9 10 rome | 8 9 10 I want to list the users whose shoppingbox does not contain "1", I m stuck about the query since it does not contain just one value. $boxitem = 1; $query = "SELECT * FROM table_user WHERE shoppingbox != $boxitem"; This query would not work I guess, ( I m aware of the problem about the design of the table, But I must use this way ) Quote Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/ Share on other sites More sharing options...
Rommeo Posted December 22, 2011 Author Share Posted December 22, 2011 any ideas ? which keyword I need to use ? Quote Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/#findComment-1300712 Share on other sites More sharing options...
suresh_kamrushi Posted December 23, 2011 Share Posted December 23, 2011 Hi Rommeo, you can try this $boxitem = 1; $query = "SELECT * FROM table_user WHERE shoppingbox REGEXP '^$boxitem | $boxitem$| $boxitem ' OR shoppingbox =$boxitem"; Suresh Quote Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/#findComment-1300811 Share on other sites More sharing options...
Rommeo Posted December 23, 2011 Author Share Posted December 23, 2011 Hi Rommeo, you can try this $boxitem = 1; $query = "SELECT * FROM table_user WHERE shoppingbox REGEXP '^$boxitem | $boxitem$| $boxitem ' OR shoppingbox =$boxitem"; Hey, I think it s the correct code and works well, but it gives me the result of datas where shoppingbox contains $boxitem, I want the results of datas where shoppingbox does NOT contain boxitem Quote Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/#findComment-1300813 Share on other sites More sharing options...
mikosiko Posted December 23, 2011 Share Posted December 23, 2011 try: $query = "SELECT * FROM table_user WHERE shoppingbox NOT REGEXP '\[\[:<:]]$boxitem\[\[:>:]]'"; Quote Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/#findComment-1300847 Share on other sites More sharing options...
fenway Posted December 24, 2011 Share Posted December 24, 2011 If the spaces are simply delimiters, then you can hack it -- replace() spaces with commas, then use FIND_IN_SET(). But you really should fix your table. Quote Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/#findComment-1301144 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.