n8w Posted May 3, 2012 Share Posted May 3, 2012 I am getting some unexpected results and I think it's because in my sql statement I am mixing up true when I want it to return just the literal match of user_id that is "1" SELECT * FROM mytable WHERE user_id='1' right now I think it's selecting everthing if the user_id is not empty .. hence it interprets user_id='1' as being true How can I write this so it selects everything from table where the user_id literally is the number 1? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/261983-user_id1-vs-user_idtrue/ Share on other sites More sharing options...
requinix Posted May 3, 2012 Share Posted May 3, 2012 What type of field is user_id? Quote Link to comment https://forums.phpfreaks.com/topic/261983-user_id1-vs-user_idtrue/#findComment-1342512 Share on other sites More sharing options...
n8w Posted May 3, 2012 Author Share Posted May 3, 2012 integer (primary key) Quote Link to comment https://forums.phpfreaks.com/topic/261983-user_id1-vs-user_idtrue/#findComment-1342513 Share on other sites More sharing options...
awjudd Posted May 3, 2012 Share Posted May 3, 2012 That is what your query is doing ... that said since it is an INTEGER, you don't need the quotes around it. SELECT * FROM mytable WHERE user_id=1 ~awjudd Quote Link to comment https://forums.phpfreaks.com/topic/261983-user_id1-vs-user_idtrue/#findComment-1342517 Share on other sites More sharing options...
n8w Posted May 3, 2012 Author Share Posted May 3, 2012 Thanks Awjudd good advice I just figured out the problem ... I was missing () on part of the statement incorrect SELECT * FROM mytable WHERE user_id=1 && c1 LIKE "%jj%" || c2 LIKE "%jj%" ORDER BY c_timestamp DESC correct SELECT * FROM mytable WHERE user_id=1 && (c1 LIKE "%jj%" || c2 LIKE "%jj%" ) ORDER BY c_timestamp DESC Quote Link to comment https://forums.phpfreaks.com/topic/261983-user_id1-vs-user_idtrue/#findComment-1342520 Share on other sites More sharing options...
awjudd Posted May 3, 2012 Share Posted May 3, 2012 Yup, that would do it ... ~awjudd Quote Link to comment https://forums.phpfreaks.com/topic/261983-user_id1-vs-user_idtrue/#findComment-1342608 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.