DamienRoche Posted February 1, 2009 Share Posted February 1, 2009 Hi Guys. Having trouble using the like statement with numbers. I have this: <?php mysql_query("SELECT * FROM pointzone WHERE range LIKE '%1%'"); ?> But that matches any number with 1 in it. How do I tell I want specifically what number I put there. NOTE: this number is dynamic so it may be 23 or 2300. EDIT: Here is an example of the range: 1,2,3,4,5,6,7,8 9,10,11,12 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/ Share on other sites More sharing options...
GingerRobot Posted February 1, 2009 Share Posted February 1, 2009 Erm, if you want to match a specific number, you dont need like: $var = 23; $result = mysql_query("SELECT * FROM pointzone WHERE range = $var") or trigger_error(mysql_error(),E_USER_ERROR); Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-752171 Share on other sites More sharing options...
DamienRoche Posted February 1, 2009 Author Share Posted February 1, 2009 Sorry, I keep forgetting to be more specific. Here is an example of the range: 1,2,3,4,5,6,7,8 9,10,11,12 I need to search within the field for the number. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-752172 Share on other sites More sharing options...
trq Posted February 1, 2009 Share Posted February 1, 2009 So your storing comma seperated strings of numbers in your database field? Why? Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-752174 Share on other sites More sharing options...
DamienRoche Posted February 1, 2009 Author Share Posted February 1, 2009 So your storing comma seperated strings of numbers in your database field? Why? Could you elaborate on why this would seem strange? Maybe there is a better way- The ranges are user defined. You choose min and max, I parse the range and insert into database in the format shown. Each range is coupled with a response. During my script, I compare a number against the range in the database and if a range is hit, then the corresponding response is given. The structure cannot be changed and needn't be. But, yeh, maybe there is a better way to match the range. I was thinking maybe it would be better if I simply recorded the min and max and then did a mysql query to match the number. thoughts? Saying that, if there is a simple query or syntax to tell mysql to only match the number I feed it in the like statement - I may as well do that. Thanks for input. Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-752178 Share on other sites More sharing options...
trq Posted February 1, 2009 Share Posted February 1, 2009 I was thinking maybe it would be better if I simply recorded the min and max and then did a mysql query to match the number. That would be the prefered option. thoughts? Saying that, if there is a simple query or syntax to tell mysql to only match the number I feed it in the like statement - I may as well do that. Remove the % from around the 1. Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-752182 Share on other sites More sharing options...
DamienRoche Posted February 1, 2009 Author Share Posted February 1, 2009 I was thinking maybe it would be better if I simply recorded the min and max and then did a mysql query to match the number. That would be the prefered option. thoughts? Saying that, if there is a simple query or syntax to tell mysql to only match the number I feed it in the like statement - I may as well do that. Remove the % from around the 1. sadly, it doesn't return any results when I do that. I think I'm going to go back and just record min and max. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-752184 Share on other sites More sharing options...
fenway Posted February 3, 2009 Share Posted February 3, 2009 FIND_IN_SET() will work, but only with numbers, and it's not fun to edit. Quote Link to comment https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/#findComment-753348 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.