From c3e2e30db0c2127717e94a5fa0401189fc54e620 Mon Sep 17 00:00:00 2001 From: Graham Cole <chckens@sucs.org> Date: Sat, 14 Jun 2008 21:00:08 +0000 Subject: [PATCH] stop things exploding when there's no junk to list --- components/junk.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/components/junk.php b/components/junk.php index 9c5e848..b1ae57b 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); -- GitLab