i want to do pagination in my php code when fetch the value from database

<? session_start();
if(!session_is_registered(myusername))
{
header("location:index.php");
}
?>
<? include("include/z_db.php");
session_start();
ob_start();

?>
<? function formatDate($date, $in = '-', $out = '-')
{
if ($date)
{
return implode($out, array_reverse(explode($in, $date)));
}
} ?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<style type="text/css">

.arrowlistmenu{
width: 170px; /*width of accordion menu*/
}

TD.norepeat{background-repeat:no-repeat;}

.arrowlistmenu .menuheader{
font: bold 12px Arial;
line-height: 26px;
color: white;
background:url(images/titlebar-active.png) no-repeat center left;
text-transform: uppercase;
padding: 0px 0px 0px 16px; /*header text is indented 10px*/
cursor: hand;
cursor: pointer;
height:27px;
}

.arrowlistmenu .openheader{ /*CSS class to apply to expandable header when it's expanded*/
background-image:url(images/titlebar.png);
}

.arrowlistmenu ul{ /*CSS for UL of each sub menu*/
list-style-type: none;
margin: 0;
padding: 0;
/*margin-bottom: 4px; bottom spacing between each UL and rest of content*/
}

.arrowlistmenu ul li{
padding-bottom: 0px; /*bottom spacing between menu items*/
}

.arrowlistmenu ul li a{
color: #ffffff;
background: url(images/arrowbullet.png) no-repeat left; /*custom bullet list image*/
display: block;
padding: 2px 0;
padding-left: 16px; /*link text is indented 19px*/
text-decoration: none;
font-weight: bold;
border-bottom: 1px dotted #dadada;
font-family:Arial, Helvetica, sans-serif;
font-size: 10px;
text-transform:uppercase;
font-weight:bold;
}

.arrowlistmenu ul li a:visited{
color: #ffffff;
}

.arrowlistmenu ul li a:hover{ /*hover state CSS*/
color: #ffffff;
background-color: #75b8f5;
}

</style>
<title>Status Report</title>

<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">

body {
background-image: url(images/bg-of-admin.gif);
margin-top: 104px;
background-color: #7FBAF0;
}

.style1 {color: #1f5689}
</style>

</head>

<body>
<!--

-->
<table width="754" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="754" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="406" height="59"><img src="images/stat_rep_txt.jpg" width="406" height="59" /></td>
<td width="348" height="59" class="keysslogo"></td>
</tr>
<tr>
<td width="406" height="60" class="admin-home-nav-bg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="22">&nbsp;</td>
<td class="admin-nav"><a class="admin-nav" href="logout.php" >Logout</a>» <a class="admin-nav" href="adminheader.php" > Back</a> </td>
</tr>
</table></td>
<td width="348" valign="top" class="admin-home-nav-bg-right">&nbsp;</td>
</tr>
</table></td>
</tr>
<tr>
<td class="main-table-bg" ><table width="754" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td width="18" valign="top" ><img src="images/admin-top-left.gif" width="18" height="76" /></td>
<td width="699" ><br />
<br />
<br />
<table width="714" border="0" cellspacing="0" cellpadding="0" class="bgstatrep" >
<tr>
<td width="4">&nbsp;</td>
<td width="76">&nbsp;</td>
<td width="79">&nbsp;</td>
<td width="95">&nbsp;</td>
<td width="179">&nbsp;</td>
<td width="57">&nbsp;</td>
<td width="55">&nbsp;</td>
<td width="51">&nbsp;</td>
<td width="61">&nbsp;</td>
<td width="44">&nbsp;</td>
<td width="13">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="head_txt">
<td>&nbsp;</td>
<td >Client Name </td>
<td >Project Name </td>
<td >Employee Name </td>
<td >Task Details </td>
<td >Date</td>
<td >Start Time </td>
<td >End Time </td>
<td >Total hrs </td>
<td >Status</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<? function status($selectsql)
{
$datfrm=$_POST['datfrm'];

//echo $datfrm=date('Y-m-d', strtotime($datefrm1));
$datto=$_POST['datto'];
$emp=$_POST['empname'];
$result=mysql_query($selectsql);



while($row=mysql_fetch_array($result )) // used for get the events form database dyanamiclly
{

$projid=$row['proj_name'];
$client=$row['client_name'];
$empname=$row['emp_name'];
$totalhours=$row['totalhrs'];
$task=$row['task_details'];
$date=$row['date'];
$stime=$row['start_time'];
$etime=$row['end_time'];
$totalhours=$row['totalhrs'];
$status=$row['status'];
?>
<tr >
<td>&nbsp;</td>
<td align="center" ><?=$client;?></td>
<td align="center"><?=$projid; ?></td>
<td align="center" ><?=$empname;?></td>
<td align="center"><textarea name="textarea" cols="25" rows="3"><?= $task;?>
</textarea></td>
<td align="center"><? echo formatDate($date);?></td>
<td align="center"><?=$stime;?></td>
<td align="center"><?=$etime;?></td>
<td align="center"><?=$totalhours;?></td>
<td align="center"><?=$status;?></td>
<td>&nbsp;</td>
</tr>
<? } ?>
<? }?>
<?
$date4=$_GET['date4'];
$pname=$_POST['project'];
$emp=$_POST['empname'];
$cname=$_POST['cname'];
$date1=$_POST['datfrm'];
$day=substr($date1,0,2);
$month=substr($date1,3,2);
$year=substr($date1,6,4);
$date= date("Y/m/d");
$datfrm=$year."-".$month."-".$day;
$date2=$_POST['datto'];
$day1=substr($date2,0,2);
$month1=substr($date2,3,2);
$year1=substr($date2,6,4);
$datto=$year1."-".$month1."-".$day1;

if($_GET['date4'])
{
$selectsql= "select * from project_progress where date ='$date'or date='$date4' order by date desc ";
echo status($selectsql);
}else if(($emp=="ALL")&& ($cname=="ALL")&& ($pname=="ALL"))
{
$selectsql="select * from project_progress where date between '$datfrm' and '$datto' order by date desc ";


echo status($selectsql);

} else if(($emp!="ALL") &&($cname!="ALL")&&($pname!="ALL"))
{
$selectsql="select * from project_progress where emp_name='$emp' and client_name='$cname' and proj_name='$pname' and date between '$datfrm' and '$datto' order by date desc ";


echo status($selectsql);

} else if(($cname=="ALL")&&($pname=="ALL")&&($emp!="ALL"))
{
$selectsql="select * from project_progress where emp_name='$emp'and date between '$datfrm' and '$datto' order by date desc ";


echo status($selectsql);
} elseif(($emp=="ALL") &&($cname=="ALL")&&($pname!="ALL"))
{
$selectsql="select * from project_progress where proj_name='$pname' and date between '$datfrm' and '$datto' order by date desc ";

// $selectsql.=" and cname=$_POST[cname] ";

echo status($selectsql);
}
elseif(($emp=="ALL") &&($cname!="ALL")&&($pname=="ALL"))
{
$selectsql="select * from project_progress where client_name='$cname'and date between '$datfrm' and '$datto' order by date desc ";

// $selectsql.=" and cname=$_POST[cname] ";
echo status($selectsql);

} elseif(($emp!="ALL") &&($cname!="ALL")&&($pname=="ALL"))
{
$selectsql="select * from project_progress where client_name='$cname' and emp_name='$emp' and date between '$datfrm' and '$datto' order by date desc ";
echo status($selectsql);
// $selectsql.=" and cname=$_POST[cname] ";


} elseif(($emp!="ALL") &&($cname=="ALL")&&($pname!="ALL"))
{
$selectsql="select * from project_progress where emp_name='$emp' and proj_name='$pname' and date between '$datfrm' and '$datto' order by date desc ";

// $selectsql.=" and cname=$_POST[cname] ";

echo status($selectsql);
} elseif(($emp=="ALL") &&($cname!="ALL")&&($pname!="ALL"))
{ $selectsql="select * from project_progress where client_name='$cname' and proj_name='$pname' and date between '$datfrm' and '$datto' order by date desc ";

// $selectsql.=" and cname=$_POST[cname] ";

echo status($selectsql);

}?>
<? if(!$_GET['date4']){?> <form action="csvfile2.php" method="get">
<input type="hidden" name="pname" value="<? echo $pname?>" />
<input type="hidden" name="cname" value="<? echo $cname?>"/>
<input type="hidden" name="ename" value="<? echo $emp?>"/>
<input type="hidden" name="datfrm" value="<? echo $datfrm?>"/>
<input type="hidden" name="datto" value="<? echo $datto?>"/>

<tr>
<td colspan="11" align="center"><input name="test" type="submit" value="download" /></td>
</tr>

</form> <? }?>
<? if($_GET['date4']) {?> <form action="csvfile2.php" method="get">


<input type="hidden" name="date" value="<? echo $date4?>"/>


<tr>
<td colspan="11" align="center"><input name="test" type="submit" value="download" /></td>
</tr>

</form><? }?>
</table>
<br />
<br /></td>
<td width="20" valign="top"><img src=" images/admin-top-right.gif" width="20" height="76" /></td>
</tr>
</table></td>
</tr>
<tr>
<td colspan="2" align="right" valign="top" ><img src="images/admin-main-table-bottom.gif" width="754" height="25" /></td>
</tr>
<tr>
<td colspan="2" align="right" valign="top" ><table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="13" height="55" valign="top"><img src="images/admin-footer-left1.gif" width="13" height="58" /></td>
<td width="724" height="58" valign="top"><table width="100%" height="54" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="bottom" bgcolor="#FFFFFF" class="admin-copyright">© 2008<a href="http://www.keysoftwareservices.co.in"> Keyss</a>. All Rights Reserved.</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#FFFFFF" class="powered-by">Powered by <a href="http://www.keysoftwareservices.co.in"> Keyss</a></td>
</tr>
</table></td>
<td width="17" height="58" valign="top"><img src="images/admin-footer-right1.gif" width="17" height="58" /></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>