Re: mySQL Query - comparing multiple values with one field

From: Date: Wed, 22 Aug 2001 08:37:40 +0000
Subject: Re: mySQL Query - comparing multiple values with one field
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-63876@lists.php.net to get a copy of this message
Hi Niklas, You can use || or OR. Secondly, huge list of values you say? Can this list be exploded by a common denominator, like a space or comma? If so, consider this: $list = // Huge list of words (array), separated by a comma. $words = explode(",", $list); $query = "SELECT * FROM table WHERE "; for($i = 0; $i <= sizeof($words); $i++) { $query .= "field LIKE '%" . $words[$i] . "%' OR "; } $query = substr($query, 0, -4); // need to take out: [[:space:]]OR[[:space:]] from the end $do_query = @mysql_query($query); Cheers, James > What I need to do is to compare if one field matches a value from a huge > list of values. > > Do I need to query like > "SELECT * FROM table WHERE field LIKE '%value1%' || field LIKE > '%value2%'" > or can I do it something like this > "SELECT * FROM table WHERE field LIKE ('%value1%' || > '%value2%')"? > > > Niklas Lampén >

« previous php.general (#63876) next »