diff --git a/components/junk.php b/components/junk.php
index 9c5e848d64a7133e18e324879d0a984babe1ce6a..b1ae57b7d72121a026de1f554e20f7922bb6baae 100644
--- a/components/junk.php
+++ b/components/junk.php
@@ -136,28 +136,30 @@ if ($mode == 'list'){
 	else{
 		$junk = $DB->GetAll("SELECT * FROM inventory WHERE status = 'junk' ORDER BY category, title, id");
 	}
-
-	// group the junk by status then by category 
-	foreach($junk as $junkitem) {
-		if ($junkitem['status'] != 'junk') {
-			$status = "unknown";
-		} else if ($junkitem['requested_by'] == null) {
-			$status = "available"; 
-		} else if ($junkitem['taken_on'] == null) {
-			$status = "requested";
-		} else {
-			$status = "taken";
-		} 
-		
-		$sortedjunk[$status][$junkitem['category']][] = $junkitem; 
-	}
-
-	$smarty->assign("junk", $sortedjunk);
-	
+	//
 	// Check there is some junk
 	if (sizeof($junk) < 1) {
 		$mode = "nojunk";
+	} else {
+
+		// group the junk by status then by category 
+		foreach($junk as $junkitem) {
+			if ($junkitem['status'] != 'junk') {
+				$status = "unknown";
+			} else if ($junkitem['requested_by'] == null) {
+				$status = "available"; 
+			} else if ($junkitem['taken_on'] == null) {
+				$status = "requested";
+			} else {
+				$status = "taken";
+			} 
+			
+			$sortedjunk[$status][$junkitem['category']][] = $junkitem; 
+		}
+		$smarty->assign("junk", $sortedjunk);
 	}
+
+	
 } else {
 	$categories = $DB->GetCol("SELECT DISTINCT category FROM inventory ORDER BY category ASC");
 	$smarty->assign("categories", $categories);