Не уверен, почему вам нужно каждый раз выбирать количество (*).Я бы предложил сделать это следующим образом:
<?php
/* establish the connection */
$mysqli = new mysqli (
'localhost', // The host to connect to
'username', // The user to connect as
'password', // The password to use
'dbname'); // The default database to query
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s<br />\n", mysqli_connect_error());
exit();
}
$perPage = 10;
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$startAt = $perPage * ($page - 1);
/* Send a query to the server */
if ($result = $mysqli->query(
"SELECT * FROM table ORDER BY title limit $startAt, $perPage")) {
$rowCnt = $result->num_rows;
echo "<h3>Page: $page</h3>\n";
/* Fetch the results of the query and show results*/
while( $row = $result->fetch_assoc() ) {
printf("%s - %s<br/>\n", $row['orderDate'], $row['orderDescription']);
}
/* Show next page, previous page links dynamically */
echo "<p>\n";
// generate previous page link if current page no is after 1st page
if ($page > 1)
printf("<a href='%s?page=%d'>Previous Page</a> \n",
$_SERVER["SCRIPT_NAME"], ($page-1));
// generate next page link if we were able to fetch $perPage rows
if ($rowCnt == $perPage)
printf("<a href='%s?page=%d'>Next Page</a>\n",
$_SERVER["SCRIPT_NAME"], ($page+1));
echo "</p>\n";
/* Destroy the result set and free the memory used for it */
$result->close();
}
/* close the connection */
$mysqli->close();
?>
Я использую новое расширение MySQL для PHP, вот справочная документация PHP MySQL