Browse Source

Improved search operators

Maurits van der Schee 10 years ago
parent
commit
6fe7f24f02
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      list.php

+ 9
- 3
list.php View File

@@ -5,7 +5,7 @@ $table = str_replace('*','%',preg_replace('/[^a-zA-Z0-9\-_*,]/','',isset($_GET["
5 5
 $callback = preg_replace('/[^a-zA-Z0-9\-_]/','',isset($_GET["callback"])?$_GET["callback"]:false);
6 6
 $page = preg_replace('/[^0-9:]/','',isset($_GET["page"])?$_GET["page"]:false);
7 7
 $filter = isset($_GET["filter"])?$_GET["filter"]:false;
8
-$match = isset($_GET["match"])&&in_array($_GET["match"],array('any','start','end','exact'))?$_GET["match"]:'start';
8
+$match = isset($_GET["match"])&&in_array($_GET["match"],array('any','start','end','exact','lower','upto','from','higher'))?$_GET["match"]:'start';
9 9
 
10 10
 $mysqli = new mysqli($config["hostname"], $config["username"], $config["password"], $config["database"]);
11 11
 
@@ -38,8 +38,14 @@ if ($filter) {
38 38
     if (count($filter)==2) {
39 39
         $filter[0] = preg_replace('/[^a-zA-Z0-9\-_]/','',$filter[0]);
40 40
         $filter[1] = $mysqli->real_escape_string($filter[1]);
41
+        $filter[2] = 'LIKE';
41 42
         if ($match=='any'||$match=='start') $filter[1] .= '%';
42 43
         if ($match=='any'||$match=='end') $filter[1] = '%'.$filter[1];
44
+        if ($match=='exact') $filter[2] = '=';
45
+        if ($match=='lower') $filter[2] = '<';
46
+        if ($match=='upto') $filter[2] = '<=';
47
+        if ($match=='from') $filter[2] = '>=';
48
+        if ($match=='higher') $filter[2] = '>';
43 49
     } else {
44 50
         $filter = false;
45 51
     }
@@ -59,7 +65,7 @@ foreach ($tables as $table) {
59 65
     echo '"'.$table.'":{';
60 66
     if (is_array($page)) {
61 67
         $sql = "SELECT COUNT(*) FROM `$table`";
62
-        if (is_array($filter)) $sql .= " WHERE `$filter[0]` LIKE '$filter[1]'";
68
+        if (is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] '$filter[1]'";
63 69
         if ($result = $mysqli->query($sql)) {
64 70
             $pages = $result->fetch_row();
65 71
             $pages = floor($pages[0]/$page[1])+1;
@@ -68,7 +74,7 @@ foreach ($tables as $table) {
68 74
     }
69 75
     echo '"columns":';
70 76
     $sql = "SELECT * FROM `$table`";
71
-    if (is_array($filter)) $sql .= " WHERE `$filter[0]` LIKE '$filter[1]'";
77
+    if (is_array($filter)) $sql .= " WHERE `$filter[0]` $filter[2] '$filter[1]'";
72 78
     if (is_array($page)) $sql .= " LIMIT $page[1] OFFSET $page[0]";
73 79
     if ($result = $mysqli->query($sql)) {
74 80
         $fields = array();

Loading…
Cancel
Save