summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Kinkade <nath@nkinka.de>2013-11-26 22:11:30 +0000
committerNathan Kinkade <nath@nkinka.de>2013-11-26 22:11:30 +0000
commit2bfa063c9a7444c701d98af50839974b0634ffdb (patch)
treea9b71e0239c472590a0bb80d2f1849659fdb18d7
parentddcfb32e729ae70de9e65d1f3e88663a7dda6f0a (diff)
Fix issue with negative search assertions.
-rw-r--r--search.php15
1 files changed, 10 insertions, 5 deletions
diff --git a/search.php b/search.php
index fde2fed..e8b5b31 100644
--- a/search.php
+++ b/search.php
@@ -123,8 +123,11 @@ if ( $name ) {
$name = trim($name);
if ( preg_match('/^-(.*)$/', $name, $matches) ) {
$where_parts_and[] = "( cases.name NOT LIKE '%{$matches[1]}%'
- OR akas.last_name NOT LIKE '{$matches[1]}%'
- OR akas.first_name NOT LIKE '{$matches[1]}%' )";
+ OR cases.id NOT IN (
+ SELECT case_id FROM akas
+ WHERE last_name LIKE '{$matches[1]}%'
+ OR first_name LIKE '{$matches[1]}%' )
+ )";
} else {
$where_parts_and[] = "( cases.name LIKE '%{$name}%'
OR akas.last_name LIKE '{$name}%'
@@ -138,7 +141,7 @@ if ( $charge ) {
foreach ( $charges as $charge ) {
$charge = trim($charge);
if ( preg_match('/^-(.*)$/', $charge, $matches) ) {
- $where_parts_and[] = "charges.charge NOT LIKE '%{$matches[1]}%'";
+ $where_parts_and[] = "cases.id NOT IN ( SELECT case_id FROM charges WHERE charge LIKE '%{$matches[1]}%' )";
} else {
$where_parts_and[] = "charges.charge LIKE '%${charge}%'";
}
@@ -150,7 +153,7 @@ if ( $disposition ) {
foreach ( $dispositions as $disposition ) {
$disposition = trim($disposition);
if ( preg_match('/^-(.*)$/', $disposition, $matches) ) {
- $where_parts_and[] = "charges.disposition NOT LIKE '%{$matches[1]}%'";
+ $where_parts_and[] = "cases.id NOT IN ( SELECT case_id FROM charges WHERE disposition LIKE '%{$matches[1]}%' )";
} else {
$where_parts_and[] = "charges.disposition LIKE '%{$disposition}%'";
}
@@ -162,7 +165,7 @@ if ( $docket ) {
foreach ( $dockets as $docket ) {
$docket = trim($docket);
if ( preg_match('/^-(.*)$/', $docket, $matches) ) {
- $where_parts_and[] = "dockets.docket NOT LIKE '%{$matches[1]}%'";
+ $where_parts_and[] = "cases.id NOT IN ( SELECT case_id FROM dockets WHERE docket LIKE '%{$matches[1]}%' )";
} else {
$where_parts_and[] = "dockets.docket LIKE '%{$docket}%'";
}
@@ -382,6 +385,8 @@ if ( $_GET['page'] && $row_count > $results_per_page ) {
echo "<br /><a href='search.php?{$_SERVER['QUERY_STRING']}&page=2'>Next Page &gt;&gt;</a>";
}
+echo "<div>$sql</div>";
+
echo <<<HTML
</body>