function dopaging($sql, $numrecords = 0, $limit = 15)
{
    global $clspg;
    global $pages;
    global $num;
    $clspg = new Pager();
    $temp = mysql_query($sql) or die(mysql_error());
    $numrows = mysql_num_rows($temp);
    $start = $clspg->findStart($limit, $numrows);
    if ($numrecords == 0) {
        $pages = $clspg->findPages($numrows, $limit);
    } else {
        if ($numrows > $numrecords) {
            $pages = $clspg->findPages($numrecords, $limit);
        } else {
            $pages = $clspg->findPages($numrows, $limit);
        }
    }
    if ($numrecords == 0) {
        $sql1 = $sql . " LIMIT " . $start . ", " . $limit;
    } else {
        if ($start + $limit > $numrecords) {
            $sql1 = $sql . " LIMIT " . $start . ", " . ($numrecords - $start);
        } else {
            $sql1 = $sql . " LIMIT " . $start . ", " . $limit;
        }
    }
    return $sql1;
}
Example #2
0
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$mysqli = mysqli_connect('localhost', 'root', '', 'bookstore');
mysqli_query($mysqli, "SET NAMES 'utf8'");
$p = new Pager();
// yêu cầu giới hạn bao nhiêu dòng
$limit = 8;
// Tìm dòng bắt đầu đưa vào trang lấy được (khai báo nếu nó chưa có giá trị)
$start = $p->findStart($limit);
// Tìm tổng số dOng với câu lệnh truy vấn
if (isset($_GET["matheloai"])) {
    $query = mysqli_query($mysqli, "SELECT * FROM sach WHERE MaTheLoai = '" . $_GET["matheloai"] . "'");
    $count = mysqli_num_rows($query);
    // Tìm số trang dựa vào số dọng và số giới hạn
    $pages = $p->findPages($count, $limit);
    $sql = "SELECT s.id, s.TuaDe, s.TacGia, s.Gia, s.NhaXuatBan, s.NamXuatBan, s.MaTheLoai,s.ImgSrc, tl.TenTheLoai FROM sach s, theloai tl WHERE s.MaTheLoai = tl.MaTheLoai AND s.MaTheLoai = '" . $_GET["matheloai"] . "' limit " . $start . "," . $limit;
    $sach = "SELECT tl.TenTheLoai, count(s.MaTheLoai) from sach s, theloai tl where s.MaTheLoai = tl.MaTheLoai AND s.MaTheLoai = '" . $_GET["matheloai"] . "' group by tl.TenTheLoai";
    $kq = mysqli_query($mysqli, $sach);
    $so = mysqli_fetch_row($kq);
    $result = mysqli_query($mysqli, $sql);
    if (mysqli_num_rows($result) != 0) {
        echo "<table align='center' width='100%'>";
        echo "<tr style='color:red; font-weight:bold'; align='center' >";
        echo "<td colspan='4' style='background-image:url(../images/danhmuc.png)' height='30'><p style='color:#FFF; font-weight:bold;  text-align:center' >Sách {$so['0']} ({$so['1']} sách)  </p></td>";
        echo "</tr>";
        $stt = 0;
        while ($row = mysqli_fetch_row($result)) {
            if ($stt % 4 == 0) {
                echo "<tr>";
            }
Example #3
0
function getListVoucher()
{
    $p = new Pager();
    /* Show many results per page? */
    $limit = 100;
    /* Find the start depending on $_GET['page'] (declared if it's null) */
    $start = $p->findStart($limit);
    /* Find the number of rows returned from a query; Note: Do NOT use a LIMIT clause in this query */
    $count = mysql_num_rows(mysql_query("SELECT * FROM wp_voucher_post"));
    /* Find the number of pages based on $count and $limit */
    $pages = $p->findPages($count, $limit);
    /* Now we use the LIMIT clause to grab a range of rows */
    $result = mysql_query("SELECT * FROM wp_voucher_post LIMIT " . $start . ", " . $limit);
    /* Now get the page list and echo it */
    $pagelist = $p->pageList($_GET['page'], $pages);
    echo $pagelist;
}