Jump to content

Recommended Posts

I have numeric values in a DB seperated by commas (The Field "NumberList" = 32754, 32775, 32780, 32781, 32782, 32783)

 

There are lots of entries that could contain the same numbers and I am searching for those IDs.

 

I am trying to code a quesry to pinpoint one set of those numbers.

 

This is all I could come up with and it isn't working.

 


$The Number="32775",

$resultSearch = mysql_query("SELECT * FROM table WHERE NumberList LIKE '$The Number' ");
while($row = mysql_fetch_array($resultSearch))
  {
  $id=$row['id'];

  echo "$id<br>"; //List all the IDs containing $TheNumber.

  

  }

 

It seems the LIKE command is definately not the answer.

 

Any help?

 

-Anthony

Link to comment
https://forums.phpfreaks.com/topic/134417-solved-comma-seperate-search/
Share on other sites

I have numeric values in a DB seperated by commas

 

This is straight up a poor design in the first place. You would be much better off normalising your data.

 

At least he lives up to his name...

 

 

-You have a space in your variable...  Did you mean $the_number?

-You're doing the like wrong. 

 

LIKE '%$the_number%' ");

 

 

There is no space in the live code.

 

$TheNumber="32775",

$resultSearch = mysql_query("SELECT * FROM table WHERE NumberList LIKE '$TheNumber' ");
while($row = mysql_fetch_array($resultSearch))
  {
  $id=$row['id'];

  echo "$id<br>"; //List all the IDs containing $TheNumber.

  

  }

 

Thank you for catching that.  Any help with the query or "normalizing" the data?

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.