views:

21

answers:

1

I have a array which store some country names

im doing a search module

and i wanna to find the db records whether contain the country names or not

but since db design problem , those record can own mutil counties and store the countries by delimiter "|"

below is a example

input: array("Cyprus","Austria") // note that the max input will be 300 country

db record country column: Albania|Andorra|Austria|Belarus|Belgium|Bosnia and Herzegovina|Bulgaria|Croatia|Cyprus|Czech Republic|Denmark|Estonia|European Union|Faroe Islands

So anyone can give a solution base on php for seaching?

A: 

First of all your DB design is not good. You should not be putting multiple delimited country names in one filed. You might wanna change it.

If you really want to work with the existing design, you can make use of explode and in_array functions of PHP as:

$db_rec = 'Albania|Andorra|Austria|Belarus|Belgium|Bosnia and Herzegovina';
$arr = explode('|',$db_rec);    
$key = 'Albania';
if(in_array($key,$arr)) {
    echo "$key found";
}
codaddict
actually the db is not design by meanyway, any regluar example instead of using in_array?
What exactly do you mean by a regluar example ?
codaddict
sorry, i mean regular expression, note that the key should be array too