Jump to content

MySQL Matching 3 Digit Patterns


DrFishNips

Recommended Posts

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

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?

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.

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.