Jump to content

mysql like - with numbers


DamienRoche

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/143400-mysql-like-with-numbers/
Share on other sites

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.

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.