mapleleaf Posted January 2, 2010 Share Posted January 2, 2010 I am trying to check if an id is in a comma separated string in the database I was using this: $query = "SELECT * FROM articles "; $query .= "WHERE second_theme IN ( ".$_POST['secondary_theme']." ) "; $_POST['secondary_theme'] is an id and second_theme is the comma separated list. What seems to be happenning is that if the id is the first in the comma separated list it will return it. If 2nd or 3rd it won't be returned? Did I misunderstand WHERE IN?? Quote Link to comment https://forums.phpfreaks.com/topic/186955-where-in-problem/ Share on other sites More sharing options...
rajivgonsalves Posted January 2, 2010 Share Posted January 2, 2010 try this $query = "SELECT * FROM articles "; $query .= "WHERE FIELD_IN_SET ( ".$_POST['secondary_theme'].", second_theme) "; the IN will compare the whole field value with the posted value Quote Link to comment https://forums.phpfreaks.com/topic/186955-where-in-problem/#findComment-987275 Share on other sites More sharing options...
mapleleaf Posted January 2, 2010 Author Share Posted January 2, 2010 I get this: #1305 - FUNCTION dbarticles.FIELD_IN_SET does not exist when running this sql: SELECT * FROM articles WHERE FIELD_IN_SET( 1, second_theme) in the message dbarticles is the database name. What is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/186955-where-in-problem/#findComment-987334 Share on other sites More sharing options...
PFMaBiSmAd Posted January 2, 2010 Share Posted January 2, 2010 It's actually FIND_IN_SET, not FIELD_IN_SET and the first parameter needs to be enclosed in single-quotes. Quote Link to comment https://forums.phpfreaks.com/topic/186955-where-in-problem/#findComment-987335 Share on other sites More sharing options...
mapleleaf Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks a lot PFMaBiSmAd!! That was what I was looking for!! Quote Link to comment https://forums.phpfreaks.com/topic/186955-where-in-problem/#findComment-987350 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.