how to show table data in page formet
<?php
session_start();
include("_incu/adminconnectdb.php");
include("_incu/func.php");
$realname=veryfy();
include("functions.php");
$id = $_GET['id'];
?>
<?php
if($id!="")
{
$query = "DELETE from contact where id='$id'";
$result = mysql_query($query) or die(mysql_error()."Couldn't update record information!");
$_SESSION['msg'] ="One Contact deleted Successfully";
header("Location: adminhome.php");
exit;
} ?>
//--------------------page no........................
<?php
//Set the page size
$PageSize = 10;
$StartRow = 0;
//Set the page no
if(empty($_GET['PageNo']))
{
if($StartRow == 0)
{
$PageNo = $StartRow + 1;
}
}
else
{
$PageNo = $_GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}
//Set the counter start
if($PageNo % $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}
//Counter End
$CounterEnd = $CounterStart + ($PageSize - 1);
?>
<?php
//------------------------end----------------------and start for search---------------
if ( $_POST["funSearch"] != "" )
{
if ( $_POST["category"] != "" )
{
$c_id =$_POST['category'];
$result = "SELECT * FROM contact where cat_id ='$c_id'" ;
$_SESSION['cate'] = $_POST['category'];
}
else
{
$_SESSION['msg'] = "Please Select Your Category";
$result = "SELECT * FROM `contact` where cat_id ='0'";
$_SESSION['cate'] = $_POST['category'];
}
if ( $result != "" )
{
$searchquery=$result ;
}
$searchquery1=$searchquery . " ORDER BY ID desc LIMIT $StartRow,$PageSize ";
$searchquery=$searchquery . " ORDER BY ID desc ";
//echo $searchquery;
$TRecord = mysql_query($searchquery);
$result = mysql_query($searchquery1);
}
//-----------------------------search end--------------------
else
{
$TRecord = mysql_query("SELECT * FROM `contact` ORDER BY ID desc");
$result = mysql_query("SELECT * FROM `contact` ORDER BY ID desc LIMIT $StartRow,$PageSize"); }
// --------------------- Total of record---------------------
$RecordCount = mysql_num_rows($TRecord);
// ------------------ Set Maximum Page----------------
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
} ?>
//--------------------------------end------------------------------
<!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=iso-8859-1" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<title>Online Phone Book Software</title>
</head>
<body>
<table border="0" cellpadding="2" cellspacing="1" width="100%">
<?php include("header.php") ?>
<tr>
<td colspan="2" class="header_separator">
<table border="0" cellspacing="0" cellpadding="4" width="100%">
<tr>
<td width="20%" class="menu_separator" valign="top">
<!-- Menu Links here -->
<?php include("links.php") ?></td>
<td width="2%" rowspan="2"> </td>
<td width="78%" rowspan="2" valign="top" class="gray_bg">
<form action="" method="post" enctype="multipart/form-data" onsubmit="">
<fieldset>
<legend><strong>Search Category By :</strong></legend>
<table width="962" height="232">
<tr>
<td height="144" colspan="3"><fieldset>
<table width="961" height="129">
<tr>
<td width="236" height="30"> </td>
<td width="88" > </td>
<td width="16"> </td>
<td width="172"> </td>
<td width="222"> </td>
<td width="199"> </td>
</tr>
<tr>
<td height="24"> </td>
<td>Category</td>
<td> </td>
<td><select name="category">
<option value="" <?php if(empty($_SESSION['cate'])){?> selected="selected" <?php }?> >---Select One---</option>
<?php $quer = "SELECT * FROM `category`";
$res = mysql_query($quer) or die(mysql_error()."Couldn't update record information!");
while ($ro = mysql_fetch_array($res))
{ ?>
<option value="<?php echo $ro['id']; ?>" <?php if($_SESSION['cate']==$ro['id']){?> selected="selected" <?php } ?> ><?php echo $ro['cat_name']; ?></option>
<?php } ?>
</select></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="24"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="39"> </td>
<td> </td>
<td> </td>
<td><input type="hidden" name="funSearch" value="1" />
<input type="submit" name="Search" value="Search" /></td>
<td><font color="red"><?php echo $msg=$_SESSION['msg']; session_unset($_SESSION['msg']) ?></font></td>
<td> </td>
</tr>
</table>
</fieldset></td>
</tr>
<tr>
<td width="960" height="80" colspan="3">
<fieldset>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr bgcolor="#EBEBEB">
<td width="5%"><div align="left"><strong>S.No</strong></div></td>
<td width="18%"><div align="left"><strong>Contact Person </strong></div></td>
<td width="18%"><div align="left"><strong>Address</strong></div></td>
<td width="12%"><div align="left"><strong>City</strong></div></td>
<td width="10%"><div align="left"><strong>State</strong></div></td>
<td width="14%"><div align="left"><strong>Mobile</strong></div></td>
<td width="13%"><div align="left"><strong>Email</strong></div></td>
<td width="10%"><div align="center"><strong>Action</strong></div></td>
</tr>
<?php //-----------------start data fetch--------------------
$i=1;
while($row = mysql_fetch_array($result))
{
$bil = $i + ($PageNo-1)*$PageSize;
?>
<tr>
<td><div align="center"><?php echo $bil; ?></div></td>
<td><div align="left"><?php echo $row['firstname']; ?></div></td>
<td><div align="left"><?php echo $row['address1']; ?></div></td>
<td><div align="left"><?php echo $row['city']; ?></div></td>
<td><div align="left"><?php echo $row['state']; ?></div></td>
<td><div align="left"><?php echo $row['mobile1']; ?></div></td>
<td><div align="left"><?php echo $row['email1']; ?></div></td>
<td><div align="center"><a href="add-contact.php?id=<?php echo $row['id']; ?>">Edit </a >/<a href="adminhome.php?id=<?php echo $row['id']; ?>"> Delete</a></div></td>
</tr>
<?php $i++;} ?> //--------------------------end of data fetch----------
<tr align="center" bgcolor="#EBEBEB">
<td colspan="8"> </td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</fieldset></form>
//-----------------------------start of numbering-------------------------
Page(s): <?php
//Print First & Previous Link is necessary
if($CounterStart != 1){
$PrevStart = $CounterStart - 1;
print "<a href=search_category.php?PageNo=1>First</a> ";
print "<a href=search_category.php?PageNo=$PrevStart>Previous</a>";
}
print " [ ";
$c = 0;
//Print Page No
for($c=$CounterStart;$c<=$CounterEnd;$c++){
if($c < $MaxPage){
if($c == $PageNo){
if($c % $PageSize == 0){
print "$c ";
}else{
print "$c | ";
}
}elseif($c % $PageSize == 0){
echo "<a href=search_category.php?PageNo=$c>$c</a> ";
}else{
echo "<a href=search_category.php?PageNo=$c>$c</a> | ";
}//END IF
}else{
if($PageNo == $MaxPage){
print "$c ";
break;
}else{
echo "<a href=search_category.php?PageNo=$c>$c</a> ";
break;
}//END IF
}//END IF
}//NEXT
echo "] ";
if($CounterEnd < $MaxPage){
$NextPage = $CounterEnd + 1;
echo "<a href=search_category.php?PageNo=$NextPage>Next</a>";
}
//Print Last link if necessary
if($CounterEnd < $MaxPage){
$LastRec = $RecordCount % $PageSize;
if($LastRec == 0){
$LastStartRecord = $RecordCount - $PageSize;
}
else{
$LastStartRecord = $RecordCount - $LastRec;
}
print " ";
echo "<a href=search_category.php?PageNo=$MaxPage>Last</a>";
}
?>
//-----------------------end----------------------------------
</td>
</tr>
<tr>
<td class="menu_separator" valign="top">
<!-- Menu Links here -->
<!-- end Menu Links here --></td>
</tr>
</table>
</td>
</tr>
<tr>
<?php include("footer.php") ?>
</tr>
</table>
</body>
</html>
Comments
Post a Comment