I'm too tired to compare your code with some that I know works, so I'll have to leave that to you right now.
Disclaimer:
(1) you shouldn't use mysql_*** functions, they've been deprecated - use PDO or mySqli instead. (PDO is more versatile)
(2) plenty of hard-coded stuff here - avoid like the plague in your own production code.
(3) no error checking done
sample-deleteMe.php
<!doctype html>
<head>
<style>
.heading
{
color: green;
font-weight: bold;
}
</style>
</head>
<body>
<?php
function createDatabase($dbName)
{
$sql = "create database ".$dbName;
mysql_query($sql);
mysql_select_db($dbName);
$sql = "CREATE TABLE IF NOT EXISTS `test` (`id` int(11) NOT NULL,`text` varchar(10) NOT NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
mysql_query($sql);
for ($i=0; $i<20; $i++)
{
$sql = "INSERT INTO `$dbName`.`test` (`id`, `text`) VALUES ('$i', 'item $i')";
mysql_query($sql);
}
}
function nukeDatabase($dbName)
{
$sql = "DROP DATABASE `$dbName`;";
mysql_query($sql);
}
$host = "localhost";
$userName="root";
$password="********";
$dbName = "cp_qa_test";
$con = mysql_connect($host,$userName,$password) or die("Unable to connect");
createDatabase($dbName);
$page = 1;
if(isset($_GET['page']))
$page = $_GET['page'];
$numPerPage = 4;
$firstRecordNum = ($page-1) * $numPerPage;
$sql = "SELECT * FROM test LIMIT $firstRecordNum,$numPerPage";
$resultSet = mysql_query($sql);
printf("Showing %d records, starting at record #%d<br>", $numPerPage, $firstRecordNum);
while ( $curRow = mysql_fetch_row($resultSet) )
{
printf("<span class='heading'>ID:</span> %d -- <span class='heading'>Text:</span> %s<br>", $curRow[0], $curRow[1]);
}
nukeDatabase($dbName);
?>
</body>
</html>