DrFishNips Posted July 8, 2009 Share Posted July 8, 2009 I'm trying to match the ID of entries with strings of text containing many different ID's. For example I have a string with ID's "19 26 126 76 193". Using this query $query = "SELECT * FROM $dbtable WHERE $page LIKE '%$item%' ORDER BY $ord" it detects all the 2 digit ID's eg. it'll display 19, 26, and 76 but it wont display the 3 digit numbers. I've tried everything do I just have to resort to using PHP outside the query? Link to comment https://forums.phpfreaks.com/topic/165171-mysql-matching-3-digit-patterns/ Share on other sites More sharing options...
beyzad Posted July 8, 2009 Share Posted July 8, 2009 <?php $str = '19 26 126 76 193'; $ids = explode(' ',$str); $temp = ''; foreach($ids as $value) { $temp .= " OR `fildname`='$value'"; } $query = "SELECT * FROM $dbtable WHERE ( 1=1 $temp) $page LIKE '%$item%' ORDER BY $ord" ?> Link to comment https://forums.phpfreaks.com/topic/165171-mysql-matching-3-digit-patterns/#findComment-870919 Share on other sites More sharing options...
DrFishNips Posted July 9, 2009 Author Share Posted July 9, 2009 Nice one thanks a lot/. Link to comment https://forums.phpfreaks.com/topic/165171-mysql-matching-3-digit-patterns/#findComment-871609 Share on other sites More sharing options...
DrFishNips Posted July 9, 2009 Author Share Posted July 9, 2009 I thought that was going to work but it didn't. If I echo the query heres what it says SELECT * FROM medicine_ailments WHERE ( 1=1 OR id='8' OR id='18') id LIKE '%8 18%' ORDER BY id It didn't display any results so I got rid of the id LIKE part and heres what the query says SELECT * FROM medicine_ailments WHERE ( 1=1 OR 'id'='8' OR id='18') Now that looks like it has it right but for some reason it just displays every single entry in that medicine ailments table. 8 and 18 are ID's of ailments in the DB so the id=18 part is right. Any idea why its displaying all the DB entries instead of just 8 and 18? Link to comment https://forums.phpfreaks.com/topic/165171-mysql-matching-3-digit-patterns/#findComment-871633 Share on other sites More sharing options...
DrFishNips Posted July 9, 2009 Author Share Posted July 9, 2009 Ah right I see whats going on here. All rows fit the criteria of 1=1 for some reason so I changed it to id='1000' and got this SELECT * FROM medicine_ailments WHERE id = '1000' OR id='8' OR id='18'Fibromyalgia, Headache in other words it works. Thanks again. Link to comment https://forums.phpfreaks.com/topic/165171-mysql-matching-3-digit-patterns/#findComment-871637 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.