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 ) 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 ? 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 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 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\[\[:>:]]'"; 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. Link to comment https://forums.phpfreaks.com/topic/253691-query-problem/#findComment-1301144 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.