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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.