Vielleicht hilft ja doch Beispielcode.
Spiel einfach mal mit den Einträgen von $beispiel rum. Mal den Parameter löschen, mal einen anderen, mal zwei, mal ganz leeres Feld; einfach rumspielen damit und das Ergebnis ansehen.
PHP-Code:
<?php
$where = '';
$beispiel = array('abc'=>'123', 'klm'=>'456', 'xyz'=>'789');
if (isset($beispiel['abc'])) {
$where .= (strlen($where)==0) ? ' WHERE ' : ' AND ';
$where .= "abc='" . (get_magic_quotes_gpc() ? $beispiel['abc'] : addslashes($beispiel['abc'])) . "'";
}
if (isset($beispiel['klm'])) {
$where .= (strlen($where)==0) ? ' WHERE ' : ' AND ';
$where .= "klm='" . (get_magic_quotes_gpc() ? $beispiel['klm'] : addslashes($beispiel['klm'])) . "'";
}
if (isset($beispiel['xyz'])) {
$where .= (strlen($where)==0) ? ' WHERE ' : ' AND ';
$where .= "xyz='" . (get_magic_quotes_gpc() ? $beispiel['xyz'] : addslashes($beispiel['xyz'])) . "'";
}
echo $where;
?>
Kommentar