<?php
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('cms', $conn);
$page = isset($_GET['p']) ? intval($_GET['p']) : 1;
if ($page < 1) $page = 1;
$limit = 14;
$offset = ($page - 1) * $limit;
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM news WHERE id < 1987 limit $offset, $limit", $conn);
$totalCurrent = mysql_num_rows($result);
echo '<ol start=' . ($offset + 1) . '>';
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
echo '<li><a href="#">' . htmlspecialchars($row['title']) . '</a></li>';
$i++;
}
while ($i++ < $limit) {
echo '<li style="color:gray;"><strike>Not Is Record</strike></li>';
}
echo '</ol>';
$result = mysql_query('SELECT FOUND_ROWS() as total', $conn);
$row = mysql_fetch_assoc($result);
$total = $row['total'];
$totalPage = ceil($total/$limit);
if ($page > 1)
echo '<a href="?p=' . 1 . '">First</a> ';
else
echo '<span>First</span> ';
if ($page > 1)
echo '<a href="?p=' . ($page - 1) . '">Prev</a> ';
else
echo '<span>Prev</span> ';
echo $page . ' ';
if ($page < $totalPage)
echo '<a href="?p=' . ($page + 1) . '">Next</a> ';
else
echo '<span>Next</span> ';
if ($page < $totalPage)
echo '<a href="?p=' . $totalPage . '">Last</a> <br />';
else
echo '<span>Last</span> <br />';
echo 'View ' . $i . ' - ' . $totalCurrent . ' records from ' . $offset . '<br />';
echo 'Total ' . $total . ' records';
mysql_close($conn);
Title:
MySQL - Paging with no SELECT COUNT(*)
Description:
<?php $conn = mysql_connect('localhost', 'root', ''); mysql_select_db('cms', $conn); $page = isset($_...
...
Rating:
4