/** * Busca a informação de todos os produtos numa categoria específica * * @access public * @param int * @return string */ public function get_in_category($id, &$pagination = null) { global $page; $data = array(); //Paginação $limit = 8; $start = 0; $counter = $this->Database->prepare("SELECT COUNT(*) as count FROM " . $this->db_table . " WHERE category_id = ? "); $counter->bind_param("i", $id); $counter->execute(); $counter->store_result(); $counter->bind_result($count); $counter->fetch(); //instancia a paginação $pagination = new Pagination($limit, $count, $page, "http://localhost/phpcart/index.php?id={$id}&page="); //Página inicial $start = $pagination->prePagination(); if ($stmt = $this->Database->prepare("SELECT id, name, price, image FROM " . $this->db_table . " WHERE category_id = ? ORDER BY id DESC LIMIT {$start}, {$limit}")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($prod_id, $prod_name, $prod_price, $prod_image); while ($stmt->fetch()) { $data[] = array('id' => $prod_id, 'name' => $prod_name, 'price' => $prod_price, 'image' => $prod_image); } $stmt->close(); } return $data; }