pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
$query = "SELECT $event_cols FROM events WHERE ";
+
+ $where = '';
+
+ if (strlen ($city)) {
+ if (strlen ($where)) $where .= "AND ";
+ $where .= sprintf ("city = '%s' ", $city);
+ }
+
+ if (strlen ($country)) {
+ if (strlen ($where)) $where .= "AND ";
+ $where .= sprintf ("country = '%s' ", $country);
+ }
+
+ if (strlen ($year)) {
+ if (strlen ($where)) $where .= "AND ";
+ $where .= sprintf ("( start >= %d AND start < %d ) ", $year, (integer)$year + 1);
+ }
+
if (strlen ($key)) {
- $where = sprintf ("name ~* '%s' OR city ~* '%s' OR url ~* '%s' OR comment ~* '%s' ",
- addslashes ($key), addslashes ($key), addslashes ($key), addslashes ($key));
- if (strlen ($country)) {
- $where = sprintf ("country = '%s' AND ( %s ) ",
- addslashes ($country), $where);
- }
- } else {
- if (strlen ($country)) {
- $where = sprintf ("country = '%s' ", addslashes ($country));
+ if (strlen ($where)) $where .= "AND ";
+ if (strlen ($city) || strlen ($country)) {
+ $where = sprintf ("( name ~* '%s' OR url ~* '%s' OR comment ~* '%s' ) ",
+ addslashes ($key), addslashes ($key), addslashes ($key));
} else {
- $where = '';
- echo "<h3>Empty search? Euh?</h3>";
+ $where = sprintf ("( name ~* '%s' OR city ~* '%s' OR url ~* '%s' OR comment ~* '%s' ) ",
+ addslashes ($key), addslashes ($key), addslashes ($key), addslashes ($key));
}
}
+ if (!strlen ($where)) {
+ echo "<h3>Empty search? Euh?</h3>";
+ }
$query .= $where . " ORDER BY start,name";
if (strlen ($where)) {