Tuesday, August 5, 2014

PAGING USING LETTERS

<html>
<head>
<title>Paging Using PHP</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass ='';

echo "<table><TR>";
for($x=65;$x<91;$x++)
{
echo "<td><a href='pagingbyletter.php?letter=",chr($x),"'>".chr($x)."</a></td>";
}
echo "</tr></table>";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('dbpractice');
/* Get total number of records */
if(!isset($_REQUEST['letter']))
{
$_REQUEST['letter']='a';
}

$sql = "SELECT eid, ename,phone ".
"FROM tblemp where ename like '".$_REQUEST['letter']."%'";
echo $sql,"<BR>";
$retval = mysql_query( $sql, $conn );

while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "EMP ID :{$row['eid']} <br> ".
"EMP NAME : {$row['ename']} <br> ".
"EMP SALARY : {$row['phone']} <br> ".
"--------------------------------<br>";
}
mysql_close($conn);
?>

No comments: