如何避免mysql查询中的许多OR语句?

I am writing a code, where I have to produce a query with many OR statements, and I think there is a more comfortable way to this than:

foreach ($plz as &$value) {
    if (empty($i)) {
        $query = "WHERE plz='$value'";
    } else {
        $query = "$query OR plz='$value'";
    }
    $i++;
}
$sql = mysql_query("SELECT * FROM table $query");
while ($data = mysql_fetch_array($sql)) {
    //do something
}

If you have multiple values a column may take, just connect them using the IN operator:

Instead of writing

... WHERE col=1 OR col=2 OR col=3

just write

... WHERE col IN (1,2,3)

To collect all entries in PHP, use an array and implode() later on:

// collecting values
$vals = array();
$vals[] = 1;
$vals[] = 2;
// ...

// add them to your query
$query .= ' WHERE col IN ( ' . implode( ',', $vals ) . ')';

// execute the query ...

In case your values are not integer, but need to be enclosed in apostrophes within the query, insert them that way into the array in the first place:

$vals[] = "'my string value'";

If the column plz is INT type, and all $plz are also integers, then:

$query = 'WHERE plz IN( ' . implode(',', $plz) . ')';

would work. Otherwise, trying this might work(not tested):

$query = 'WHERE plz IN( \'' . implode("','", $plz) . '\')';

You're looking for ;

SELECT * FROM table WHERE plz in ('value1', 'value2', 'value3')

Be aware of SQL injections...