Pagination Error?..
Posted: Mon Jun 25, 2007 8:46 pm
Ok i started to make a pagination code for my website, but what i expected did not occur, either way here is my database relating to the code..
As for this is the actual code.
AS FOR THE UNWANTED RESULT
=========================================
Successful database connection
There are no records found!
=========================================
Please tell me whats wrong
btw, its php5
thanks in advance
Code: Select all
SQL result
Host: localhost
Database: news
Table : news
Rows: 6
=================================================================
id | title | news
=================================================================
1 A ABC
2 Ab ABC
3 Ac ABC
4 Ad ABC
5 Ae ABC
6 Af ABCCode: Select all
<?php
//Database connection:
$user = "root3";
$pass = "password3";
$host = "localhost";
$db = "news";
$con = mysql_connect($host,$user,$pass);
mysql_select_db($db,$con) or die(mysql_error());
if ($con){
echo "Successful database connection<br>";
} else {
echo "No successful connection<br>";
}
$pageNumber = (isset($_GET["page"]) && is_numeric($_GET["page"])) ? $_GET["page"] : 1;
// Results per page
$perPage = 6;
// Establish a padding value
$padding = 3;
// Get start index of results
$startIndex = ($pageNumber * $perPage) - ($perpage - 1);
// Get total number of database entries
$totalCount = "SELECT COUNT(*) as 'Total' FROM news.news";
$rsCount = mysql_query($totalCount, $con) or die(mysql_error());
$rowCount = mysql_fetch_object($rsCount);
// Get page results
$sql = "SELECT id, title, news
FROM news ORDER BY id
LIMIT $startIndex, $perPage";
// Get result set
$rs = mysql_query($sql,$con) or die(mysql_error());
// Do we have results?
if(mysql_num_rows($rs) > 0) {
// Show results:
while($row = mysql_fetch_object($rs)) {
print "<div>";
print $row->id . "<br>";
print "<strong>" . $row->title . "</strong><p>";
print ": ";
print $row->news . "</div><br>";
}
} else {
print "There are no records found!";
}
// Close the database connection
mysql_close($con);
?>=========================================
Successful database connection
There are no records found!
=========================================
Please tell me whats wrong
btw, its php5
thanks in advance