i am trying to do a pagination but, i cant seem to get the problem..
<?
//pagination
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("custech");
$strSQL = "SELECT * FROM proposals ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$Num_Rows = mysql_num_rows($objQuery);
$Per_Page = 4; // Per Page
$Page = $_GET["Page"];
if(!$_GET["Page"])
{
$Page=1;
}
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows<=$Per_Page)
{
$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
$Num_Pages =($Num_Rows/$Per_Page)+1;
$Num_Pages = (int)$Num_Pages;
}
// Before using $_POST['value'] add this - to avoid error on undefined index
if (!isset($_POST['txtSearch']))
{
//Instruction if $_POST['value']doesnt exist
$_POST['txtSearch']="%";
}
//to select all record in database and to display all records
if($levelbox=='')
{
$sql="SELECT * FROM proposals ORDER BY pro_id ASC LIMIT $Page_Start , $Per_Page";
}
else {
$strSQL .=" SELECT * FROM proposals WHERE $levelbox LIKE '%".$_POST['txtSearch']."%' ORDER BY pro_id ASC LIMIT $Page_Start , $Per_Page";
//$sql="SELECT * FROM proposals WHERE $levelbox LIKE '%".$_POST['txtSearch']."%' ORDER BY pro_id ASC";
}
//$sql="SELECT * FROM robots WHERE $levelbox LIKE '%".$_POST['txtSearch']."%'";
$objQuery = mysql_query($strSQL);
//$result=mysql_query($sql);
//error message if query fails
if (!$objQuery)
{
die;
exit;
}
//if no records found
if (mysql_num_rows($objQuery)==0)
{
echo "<table cellspacing='0' cellpading='3'><tr><td>";
echo "No row found, no row to print, so, am exiting";
echo "</td></tr></table>";
exit;
}
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Proposal ID </div></th>
<th width="98"> <div align="center">Proposal Name </div></th>
<th width="198"> <div align="center">Company </div></th>
<th width="97"> <div align="center">Proposl Date </div></th>
<th width="59"> <div align="center">Proposal Status</div></th>
<th width="60"> <div align="center">File</div></th>
<th width="71"> <div align="center">Proposal By</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["pro_id"];?></div></td>
<td><?=$objResult["pro_name"];?></td>
<td><?=$objResult["pro_company"];?></td>
<td><div align="center"><?=$objResult["pro_date"];?></div></td>
<td align="right"><?=$objResult["pro_status"];?></td>
<td align="right"><a href="<?=$objResult["pro_file"];?>">DOWNLOAD</a></td>
<td align="right"><?=$objResult["pro_by"];?></td>
</tr>
<?
}
?>
</table>
<br>
Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page :
<?
if($Prev_Page)
{
echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page'><< Back</a> ";
}
for($i=1; $i<=$Num_Pages; $i++){
if($i != $Page)
{
echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i'>$i</a> ]";
}
else
{
echo "<b> $i </b>";
}
}
if($Page!=$Num_Pages)
{
echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page'>Next>></a> ";
}
mysql_close($objConnect);
//end of pagination
?>