public function getProductsByIdShop($records_per_page = null) { $pagination = new Zebra_Pagination(); // set position of the next/previous page links $pagination->navigation_position(isset($_GET['navigation_position']) && in_array($_GET['navigation_position'], array('left', 'right')) ? $_GET['navigation_position'] : 'outside'); $records_per_page = $records_per_page == null ? 25 : $records_per_page; $db = PDOQuery::getInstance(); $db->connect(); $sql = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT product_lang.product, product.id_product, stock_available.stock_available, stock_available.price, product.reference FROM product_lang RIGHT JOIN product ON product.id_product = product_lang.id_product RIGHT JOIN stock_available ON product.id_product = stock_available.id_product WHERE stock_available.id_shop = :id_shop1 AND product_lang.id_lang=' . _ID_LANG_ . $_SESSION['adminQuery'] . ' UNION SELECT DISTINCT product_lang.product, product.id_product, stock_available.stock_available, stock_available.price, product.reference FROM product_lang RIGHT JOIN product ON product.id_product = product_lang.id_product RIGHT JOIN stock_available ON product.id_product = stock_available.id_product RIGHT JOIN product_tag ON product_tag.id_product = product.id_product RIGHT JOIN tags ON tags.id_tag = product_tag.id_tag WHERE stock_available.id_shop = :id_shop2 AND product_lang.id_lang=' . _ID_LANG_ . ' AND tags.tag = :tagQuery ORDER BY id_product asc LIMIT ' . ($pagination->get_page() - 1) * $records_per_page . ', ' . $records_per_page; $stmt = $db->prepareQuery($sql); $stmt->bindParam(':id_shop1', $_SESSION['id_shop'], PDO::PARAM_INT); $stmt->bindParam(':id_shop2', $_SESSION['id_shop'], PDO::PARAM_INT); $stmt->bindParam(':tagQuery', $_SESSION['tagQuery'], PDO::PARAM_STR); $stmt->execute(); $rows = $db->query('SELECT FOUND_ROWS();')->fetch(PDO::FETCH_COLUMN); // pass the total number of records to the pagination class $pagination->records($rows); // records per page $pagination->records_per_page($records_per_page); $this->pagination_render = $pagination->render(); $db->close(); return $stmt; }
public function getTotalSaleList($id_order_by = null, $records_per_page = null) { $pagination = new Zebra_Pagination(); // set position of the next/previous page links $pagination->navigation_position(isset($_GET['navigation_position']) && in_array($_GET['navigation_position'], array('left', 'right')) ? $_GET['navigation_position'] : 'outside'); $records_per_page = $records_per_page == null ? 15 : $records_per_page; $db = PDOQuery::getInstance(); $db->connect(); $order_by = $this->orderBySwitcher($id_order_by); $asc = $this->getOrderDirection(); $sql = "SELECT SQL_CALC_FOUND_ROWS DISTINCT \n\t\t\t\t\tSUM(sales.amount) as total,\n\t\t\t\t\tsales.id_shop_session,\n\t\t\t\t\tshop_session.date\n\t\t\t\tFROM \tsales\n\t\t\t\t\tINNER JOIN shop_session ON shop_session.id_shop_session = sales.id_shop_session\n\t\t\t\tWHERE \tshop_session.id_shop = " . $_SESSION['id_shop'] . "\n\t\t\t\tAND \tshop_session.is_active = 0\n\t\t\t\tGROUP BY shop_session.id_shop_session\n\t\t\t\tORDER BY {$order_by} {$asc}\n\t\t\t\tLIMIT\n \t\t\t\t" . ($pagination->get_page() - 1) * $records_per_page . ", " . $records_per_page; $stmt = $db->prepareQuery($sql); $stmt->bindParam(':id_shop', $_SESSION['id_shop'], PDO::PARAM_INT); $stmt->execute(); $rows = $db->query('SELECT FOUND_ROWS();')->fetch(PDO::FETCH_COLUMN); // pass the total number of records to the pagination class $pagination->records($rows); // records per page $pagination->records_per_page($records_per_page); $this->pagination_render = $pagination->render(); $db->close(); return $stmt; }
</head> <body> <h2>Zebra_Pagination, database example</h2> <p>For this example, you need to first import the <strong>countries.sql</strong> file from the examples folder and to edit the <strong>example2.php file and change your database connection related settings.</strong></p> <p>Show next/previous page links on the <a href="example2.php?navigation_position=left">left</a> or on the <a href="example2.php?navigation_position=right">right</a>. Or revert to the <a href="example2.php">default style</a>.<br> Pagination links can be shown in <a href="example2.php">natural</a> or <a href="example2.php?direction=reversed">reversed</a> order.<br> See the <a href="example2.php">default</a> looks or with <a href="example2.php?bootstrap=1">Bootstrap</a><br> <em>(when using Bootstrap you don't need to include the zebra_pagination.css file anymore)</em></p> <?php // database connection details $MySQL_host = ''; $MySQL_username = ''; $MySQL_password = ''; $MySQL_database = ''; // if could not connect to database if (!($connection = @mysql_connect($MySQL_host, $MySQL_username, $MySQL_password))) { // stop execution and display error message die('Error connecting to the database!<br>Make sure you have specified correct values for host, username and password.'); } // if database could not be selected if (!@mysql_select_db($MySQL_database, $connection)) { // stop execution and display error message die('Error selecting database!<br>Make sure you have specified an existing and accessible database.'); } // how many records should be displayed on a page? $records_per_page = 10; // include the pagination class require '../Zebra_Pagination.php';