jk11uk Posted August 3, 2009 Share Posted August 3, 2009 hi ive got a column of keywords and all i want to do is select * where keyword='KEYWORD'. so my query is: SELECT * FROM `keywords` WHERE `keyword` = 'ppi' now i have the string 'ppi' in the column, but it wont select it! The annoying thing is i went into phpmyadmin and tried it, no luck. then went into that entry, deleted 'ppi' and replaced with ccc. the search could find 'ccc'! WTF? i then changed back to 'ppi' and it could find that. this happens with every string i have in this column. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/ Share on other sites More sharing options...
dreamwest Posted August 3, 2009 Share Posted August 3, 2009 You could have spaces in you keyword column _ppi Try: SELECT * FROM `keywords` WHERE `keyword` LIKE 'ppi' Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/#findComment-890145 Share on other sites More sharing options...
jk11uk Posted August 3, 2009 Author Share Posted August 3, 2009 no i wish . no spaces. LIKE doesnt work either thanks though Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/#findComment-890150 Share on other sites More sharing options...
o3d Posted August 4, 2009 Share Posted August 4, 2009 try select * from keywords where keyword like '%ppi%' if no rows are returned, then try select distinct keyword from keywords and see what values are available for keyword Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/#findComment-890272 Share on other sites More sharing options...
jk11uk Posted August 4, 2009 Author Share Posted August 4, 2009 thank you so much. I've been scratching my head over this (and tearing hair out) for at least 4 hours the code worked. What do the %'s mean? Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/#findComment-890340 Share on other sites More sharing options...
jk11uk Posted August 4, 2009 Author Share Posted August 4, 2009 although the problem now is, say i search for %ppi%, it also returns anything with 'ppi' in - not exact matches (which is what i need). I can use php to sift out the non-exact matches but as this is not efficient do you know what to do? if not i'll go with inefficiency Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/#findComment-890342 Share on other sites More sharing options...
kickstart Posted August 4, 2009 Share Posted August 4, 2009 Hi The % is a wildcard. It is matching for zero or more characters. Original problem was probably that ppi in the table probably had a leading or trailing space. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/168718-nightmare-sql-problem/#findComment-890412 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.