I have developed a code for pagination in my application with php and mysql. By passing page numbers in querystring with a question mark,but i want to pass the page number parameter with hash instead of question mark.Following is my code with question mark,Please help me in passing page number parameter with a hash sign in url instead of question mark.Help guys.
<html>
<head>
<title>Paging Using PHP</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$rec_limit = 10;
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('dbname');
/* Get total number of records */
$sql = "SELECT count(*) FROM tablename";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
if( isset($_GET{'page'} ) )
{
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}
else
{
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$sql = "SELECT col1,col2,col3 FROM tablename LIMIT $offset, $rec_limit";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "EMP ID :{$row['col1']} <br> ".
"EMP NAME : {$row['col2']} <br> ".
"EMP SALARY : {$row['col3']} <br> ".
"--------------------------------<br>";
}
if( $page > 0 )
{
$last = $page - 2;
echo "<a href=\"pagination2.php?page=$last\">Last 10 Records</a> |";
echo "<a href=\"pagination2.php?page=$page\">Next 10 Records</a>";
}
else if( $page == 0 )
{
echo "<a href=\"pagination2.php?page=$page\">Next 10 Records</a>";
}
else if( $left_rec < $rec_limit )
{
$last = $page - 2;
echo "<a href=\"$_PHP_SELF?page=$last\">Last 10 Records</a>";
}
mysql_close($conn);
?>
Please help me in passing page number parameter with hash parameter