phpretard Posted November 26, 2008 Share Posted November 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
trq Posted November 26, 2008 Share Posted November 26, 2008 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. Quote Link to comment Share on other sites More sharing options...
phpretard Posted November 26, 2008 Author Share Posted November 26, 2008 Could you elaborate on ... "normalising your data"? Quote Link to comment Share on other sites More sharing options...
Maq Posted November 26, 2008 Share Posted November 26, 2008 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%' "); Quote Link to comment Share on other sites More sharing options...
phpretard Posted November 26, 2008 Author Share Posted November 26, 2008 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? Quote Link to comment Share on other sites More sharing options...
Maq Posted November 26, 2008 Share Posted November 26, 2008 Have you fixed the LIKE clause? I can't test right now so I'm not sure if it will work. Quote Link to comment Share on other sites More sharing options...
phpretard Posted November 26, 2008 Author Share Posted November 26, 2008 Thank you for your help ... My eyes are bugging out It was the %% ... I knew that . Also...All your criticism is straight up appriciated! Quote Link to comment Share on other sites More sharing options...
Maq Posted November 26, 2008 Share Posted November 26, 2008 Thank you for your help ... My eyes are bugging out It was the %% ... I knew that . Then why did you ask?! J/k. Quote Link to comment 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.