Comparing string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Comparing string

Post by shivam0101 »

How do i fetch values from a table which will contain 2 characters

Example, field contains:

1. A123BCDE
2. A123CDEB
3. A123CEBF
4. A12CEBD3

and i want all the field values which contain CD.

i should get
1
2
4
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Comparing string

Post by Chris Corbyn »

shivam0101 wrote:How do i fetch values from a table which will contain 2 characters

Example, field contains:

1. A123BCDE
2. A123CDEB
3. A123CEBF
4. A12CEBD3

and i want all the field values which contain CD.

i should get
1
2
4

Code: Select all

if (strstr($input, "C") && strstr($input, "D")) {
  //Then $input contains both C and D
}
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

Is it possible to get this values using only sql statment?
paulbm
Forum Newbie
Posts: 5
Joined: Tue Sep 25, 2007 8:13 am

Post by paulbm »

Code: Select all

select string_field from strings_table where string_field like '%CD%'
Post Reply