Jump to content

[SOLVED] Comma Seperate Search


phpretard

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?

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.