I am having records in a field (field_id) of a table (in mysql database), which is having ID stored per line, for example

1
2
3
10
11
13


above is one record, and I have many records similar to that.

and, when I am writing the query SELECT * FROM $table_name where field_id like '%1%'

then the rows having the results like
10
11
13

are also returned. I am upset. How to overcome this problem?

I found one fix to this, but it fails in most of the conditions, this is -

SELECT * FROM `$table_name` WHERE field_id like '%\n1%' OR '%1\n%'

This fails, when the (field_id) have only one record, for example, '1'. I want to catch everything, where line equals to 1, whether single line in the record, or many.

I am going mad for this.

Can someone provide me any way? Thanks.

Recommended Answers

All 3 Replies

Hi mohansinhf,

If I understand correctly, you are trying to return all records that are equal to 1.

Try the following:

SELECT * FROM $table_name where field_id = '1'

Regards

Check this out,it will work if i understood properly...

SELECT * FROM `$table_name` WHERE field_id like '%\n1%' OR field_id like '%1\n%' OR 
field_id like '1'

Hope it works :)

Thanks Akash Saikia and trilithon. You both gave me good solutions. Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.