diff --git a/api_db.php b/api_db.php
index a36e1bb005728898e55f9124aa8007c60d4f319b..320a9a314fa6147440b85ab0f3df7d7269525748 100644
--- a/api_db.php
+++ b/api_db.php
@@ -168,9 +168,26 @@ if (isset($_GET['topClients']) && $auth)
 	{
 		$limit = "WHERE timestamp <= :until";
 	}
+
+	if(isset($_GET["client"]) && strlen($_GET["client"]) > 0)
+	{
+		$limit .= " AND client = :client";
+		$client = urldecode($_GET["client"]);
+	}
+
+	if(isset($_GET["domain"]) && strlen($_GET["domain"]) > 0)
+	{
+		$limit .= " AND domain = :domain";
+		$domain = urldecode($_GET["domain"]);
+	}
+
 	$stmt = $db->prepare('SELECT client,count(client) FROM queries '.$limit.' GROUP by client order by count(client) desc limit 20');
 	$stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER);
 	$stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER);
+	if(isset($client))
+		$stmt->bindValue(":client", $client, SQLITE3_TEXT);
+	if(isset($domain))
+		$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
 	$results = $stmt->execute();
 
 	$clientnums = array();
@@ -219,9 +236,26 @@ if (isset($_GET['topDomains']) && $auth)
 	{
 		$limit = " AND timestamp <= :until";
 	}
+
+	if(isset($_GET["client"]) && strlen($_GET["client"]) > 0)
+	{
+		$limit .= " AND client = :client";
+		$client = urldecode($_GET["client"]);
+	}
+
+	if(isset($_GET["domain"]) && strlen($_GET["domain"]) > 0)
+	{
+		$limit .= " AND domain = :domain";
+		$domain = urldecode($_GET["domain"]);
+	}
+
 	$stmt = $db->prepare('SELECT domain,count(domain) FROM queries WHERE (STATUS == 2 OR STATUS == 3)'.$limit.' GROUP by domain order by count(domain) desc limit 20');
 	$stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER);
 	$stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER);
+	if(isset($client))
+		$stmt->bindValue(":client", $client, SQLITE3_TEXT);
+	if(isset($domain))
+		$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
 	$results = $stmt->execute();
 
 	$domains = array();
@@ -269,9 +303,26 @@ if (isset($_GET['topAds']) && $auth)
 	{
 		$limit = " AND timestamp <= :until";
 	}
+
+	if(isset($_GET["client"]) && strlen($_GET["client"]) > 0)
+	{
+		$limit .= " AND client = :client";
+		$client = urldecode($_GET["client"]);
+	}
+
+	if(isset($_GET["domain"]) && strlen($_GET["domain"]) > 0)
+	{
+		$limit .= " AND domain = :domain";
+		$domain = urldecode($_GET["domain"]);
+	}
+
 	$stmt = $db->prepare('SELECT domain,count(domain) FROM queries WHERE (STATUS == 1 OR STATUS == 4)'.$limit.' GROUP by domain order by count(domain) desc limit 10');
 	$stmt->bindValue(":from", intval($_GET['from']), SQLITE3_INTEGER);
 	$stmt->bindValue(":until", intval($_GET['until']), SQLITE3_INTEGER);
+	if(isset($client))
+		$stmt->bindValue(":client", $client, SQLITE3_TEXT);
+	if(isset($domain))
+		$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
 	$results = $stmt->execute();
 
 	$addomains = array();
diff --git a/db_lists.php b/db_lists.php
index 137922775395273b89e5b75b41125012d822a7cb..55665ea7f181607ec9a51dfdfabc34fd2041d15c 100644
--- a/db_lists.php
+++ b/db_lists.php
@@ -22,21 +22,43 @@ $token = $_SESSION['token'];
     <h1>Compute Top Lists from the Pi-hole query database</h1>
 </div>
 
-
 <div class="row">
     <div class="col-md-12">
-<!-- Date Input -->
-      <div class="form-group">
-        <label>Date and time range:</label>
-
-        <div class="input-group">
-          <div class="input-group-addon">
-            <i class="far fa-clock"></i>
-          </div>
-          <input type="button" class="form-control pull-right" id="querytime" value="Click to select date and time range">
+        <div class="box">
+            <!-- /.box-header -->
+            <div class="box-header with-border">
+                <h3 class="box-title">
+                    Request information from Pi-hole's long-term database
+                </h3>
+            </div>
+            <!-- /.box-header -->
+            <div class="box-body">
+                <div class="row">
+                    <div class="col-md-12">
+                        <!-- Date Input -->
+                        <div class="form-group">
+                            <label>Date and time range:</label>
+                            <div class="input-group">
+                            <div class="input-group-addon">
+                                <i class="far fa-clock"></i>
+                            </div>
+                            <input type="button" class="form-control pull-right" id="querytime" value="Click to select date and time range">
+                        </div>
+                        </div>
+                    </div>
+                </div>
+                <div class="row">
+                    <div class="col-md-6">
+                        <label for="client">Limit to specific client:</label>
+                        <input id="client" type="url" class="form-control" placeholder="Leave empty for all clients" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
+                    </div>
+                    <div class="col-md-6">
+                        <label for="domain">Limit to specific domain:</label>
+                        <input id="domain" type="url" class="form-control" placeholder="Leave empty for all domains" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
+                    </div>
+                </div>
+            </div>
         </div>
-        <!-- /.input group -->
-      </div>
     </div>
 </div>
 
diff --git a/scripts/pi-hole/js/db_lists.js b/scripts/pi-hole/js/db_lists.js
index 3f055fe801e7353a8d8a52df6250a291edf3eb28..9cede2f3f64128eb242371151c7f2f72b2c9d4ba 100644
--- a/scripts/pi-hole/js/db_lists.js
+++ b/scripts/pi-hole/js/db_lists.js
@@ -89,7 +89,11 @@ function escapeHtml(text) {
 
 function updateTopClientsChart() {
   $("#client-frequency .overlay").show();
-  $.getJSON("api_db.php?topClients&from=" + from + "&until=" + until, function(data) {
+
+  var client = encodeURIComponent($("#client").val());
+  var domain = encodeURIComponent($("#domain").val());
+
+  $.getJSON("api_db.php?topClients&from=" + from + "&until=" + until + "&client=" + client + "&domain=" + domain, function(data) {
     // Clear tables before filling them with data
     $("#client-frequency td")
       .parent()
@@ -145,7 +149,11 @@ function updateTopClientsChart() {
 
 function updateTopDomainsChart() {
   $("#domain-frequency .overlay").show();
-  $.getJSON("api_db.php?topDomains&from=" + from + "&until=" + until, function(data) {
+
+  var client = encodeURIComponent($("#client").val());
+  var domain = encodeURIComponent($("#domain").val());
+
+  $.getJSON("api_db.php?topDomains&from=" + from + "&until=" + until + "&client=" + client + "&domain=" + domain, function(data) {
     // Clear tables before filling them with data
     $("#domain-frequency td")
       .parent()
@@ -194,7 +202,11 @@ function updateTopDomainsChart() {
 
 function updateTopAdsChart() {
   $("#ad-frequency .overlay").show();
-  $.getJSON("api_db.php?topAds&from=" + from + "&until=" + until, function(data) {
+
+  var client = encodeURIComponent($("#client").val());
+  var domain = encodeURIComponent($("#domain").val());
+
+  $.getJSON("api_db.php?topAds&from=" + from + "&until=" + until + "&client=" + client + "&domain=" + domain, function(data) {
     // Clear tables before filling them with data
     $("#ad-frequency td")
       .parent()
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index a8596b8fade0ee2f5a7d27fc40dbf00096968979..667e3807bdab1e7f940f87a32d4109e05b8ad272 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -283,6 +283,7 @@ $(document).ready(function() {
           }
         );
         $("td:eq(4)", row).click(function() {
+          console.log("Adding");
           var new_tab = window.open("groups-domains.php?domainid=" + data[9], "_blank");
           if (new_tab) {
             new_tab.focus();