public function index() { $total = 0; $this->db->setQuery('SELECT count(*)' . ' FROM #__acctexp_' . $this->table . $this->getConstraints()); $total += $this->db->loadResult(); $this->db->setQuery('SELECT count(*)' . ' FROM #__acctexp_coupons_static' . $this->getConstraints()); $nav = $this->getPagination($total + $this->db->loadResult()); // get the subset (based on limits) of required records $query = '(SELECT *, "0" as `type`' . ' FROM #__acctexp_coupons' . $this->getConstraints() . ')' . ' UNION ' . '(SELECT *, "1" as `type`' . ' FROM #__acctexp_coupons_static' . $this->getConstraints() . ')' . $this->getOrdering() . $this->getLimit(); $this->db->setQuery($query); $rows = $this->db->loadObjectList(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } $query = 'SELECT SUM(usecount)' . ' FROM #__acctexp_coupons'; $this->db->setQuery($query); $total_usecount = $this->db->loadResult(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } $query = 'SELECT SUM(usecount)' . ' FROM #__acctexp_coupons_static'; $this->db->setQuery($query); $total_usecount += $this->db->loadResult(); if ($this->db->getErrorNum()) { echo $this->db->stderr(); return false; } foreach ($rows as $rid => $row) { if ($row->usecount) { $rows[$rid]->percentage = $row->usecount / ($total_usecount / 100); } else { $rows[$rid]->percentage = 0; } $rows[$rid]->inner = false; if ($rows[$rid]->percentage > 15) { $rows[$rid]->inner = true; } } HTML_AcctExp::listCoupons($rows, $this->state, $nav); }