summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2014-01-10 21:48:45 +0000
committerNathan Kinkade <nath@nkinka.de>2014-01-10 21:48:45 +0000
commit5e731b85742e01abafce2bdf4482d288d9d1299b (patch)
tree30931f4c9e19a27be262a8616cfa45c9fd23a56c
parentec5e9062a92fec78ee7f01e6623230658b5db595 (diff)
It would appear that where clause order does matter, and significantly, at least in terms of these queries on the dockets table.
-rw-r--r--search.php28
1 files changed, 14 insertions, 14 deletions
diff --git a/search.php b/search.php
index de29810..42b9218 100644
--- a/search.php
+++ b/search.php
@@ -69,7 +69,7 @@ foreach ( $request_params as $param => $value ) {
}
$select = "SELECT DISTINCT cases.* FROM cases ";
-$select_num_rows = "SELECT DISTINCT count(cases.id) FROM cases ";
+$select_num_rows = "SELECT count(DISTINCT cases.id) FROM cases ";
if ( $charge || $disposition ) {
$select .= "LEFT JOIN charges ON cases.id = charges.case_id ";
@@ -234,34 +234,35 @@ if ( $docket ) {
$where = '';
-if ( $where_parts_and ) {
- foreach ( $where_parts_and as $and_part ) {
+if ( $where_parts_or ) {
+ foreach ( $where_parts_or as $or_part ) {
if ( $where ) {
- $where .= " AND $and_part";
+ $where .= " OR $or_part";
} else {
- $where = "WHERE $and_part";
+ $where = "WHERE $or_part";
}
}
}
-if ( $where_parts_or ) {
- // The first element of the OR list should be appended to the existing
+if ( $where_parts_and ) {
+ // The first element of the AND list should be appended to the existing
// where clause with an AND
if ( $where ) {
- $where .= " AND " . array_shift($where_parts_or);
+ $where .= " AND " . array_shift($where_parts_and);
}
- // If there are still any where_parts_or left, then join them with OR
- if ( count($where_parts_or) ) {
- foreach ( $where_parts_or as $or_part ) {
+ // If there are still any where_parts_or left, then join them with AND
+ if ( count($where_parts_and) ) {
+ foreach ( $where_parts_and as $and_part ) {
if ( $where ) {
- $where .= " OR $or_part";
+ $where .= " AND $and_part";
} else {
- $where = "WHERE $or_part";
+ $where = "WHERE $and_part";
}
}
}
}
+
if ( empty($where) ) {
echo "You must enter at least one search criteria.";
exit;
@@ -315,7 +316,6 @@ if ( $_GET['page'] ) {
$sql .= " LIMIT 0, $results_per_page";
}
-
$st = $dbh->prepare($sql);
if ( $st->execute() ) {
echo <<<HTML