Sunday, May 26, 2013

PHP pagination with css

<!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" />
<title>Untitled Document</title>
<style type="text/css">
a#select_a
{
    background-color:#FFCCCC;//#ABD1D8;
    color:#000000;
    font-weight:600;
}
a
{
    border:outset;
    border-width:thin;
    padding-left:4px;
    padding-right:4px;
    color:#0033FF;
    border-color:#400080;
    background-color:#ABD1D8;//#FFCCCC;
    text-decoration: none;
    margin-left:14px;
}

th#id_th
{
    width:1px;
}
th
{
    width:350px;
}
td
{
text-align:center;

}
</style>

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">
</script>

<script type="text/javascript">
function del(id)
{
    alert(id);

    $.ajax({
            type: "POST",
            url: "d.php",
            data: {id:id},
            //dataType: "JSON",
            success: function(msg){
                alert(msg);
            }
         });
       
        alert("hhi");   
    $('tr#'+id).slideUp(1000);
}
function add_emp()
{
    var form_data=$("form").serialize();
    alert(form_data);
    var data=form_data.unserialize();
    alert('hi');
   
}

</script>
</head>

<body>
<?php
$conn = mysql_connect("localhost", "root", "") or die("db server not connected");
mysql_selectdb("db_test",$conn) or die('not seleected db');
?>
<form name="form_add_emp" id="form_add_employee" method="post">
    Employee Type:
    <input type="text" id="emp_type" name=="emp_type" />
    <input type="submit" value="Add" onclick="add_emp();"/>
</form>
<?php
$limit=10;

$result1=mysql_query("select * from  tbl_employee_type order by type_id",$conn) or die('res not feteched');
echo $num_rows=mysql_num_rows($result1);
echo $num_pages=ceil($num_rows/$limit);


if(isset($_GET['page_no']))
{
    $page_no=$_GET['page_no'];
    $offset=($_GET['page_no']-1)*$limit;
}
else
{
    $page_no=1;
    $offset=0;
}
$result=mysql_query("select * from  tbl_employee_type order by type_id LIMIT ".$offset.",".$limit,$conn) or die('res not feteched');
?>
<form method="post" action="mul_del.php" name="mul_del" id="mul_del">
<input type="submit" value="delete" />
<table style="background-color:"white";">
<tr style="background-color:#BCA5D8;">
    <th id="id_th">
        Checkboxes
    </th>
    <th id="id_th">
        Id
    </th>
    <th>
        Employee type
    </th>
    <th>
        modify date
    </th>
    <th>
    Action
    </th>
</tr>

<?php
$i=1;
while($row = mysql_fetch_array($result))
{
?>
<tr id=<?php echo $row['type_id']; ?>>   
    <td style="background-color:#B4C2F5;">
    <input type="checkbox" name="checkbox<?php echo $row['type_id'];?>" id="checkbox" value="<?php echo $row['type_id']; ?>" />
    </td>
    <td style="background-color:#B4C2F5;">
    <?php echo $row['type_id']; ?>
    </td>
    <td style="background-color:#F8D2F9;">
    <?php echo $row['employee_type']; ?>
    </td>
    <td style="background-color:#B4C2F5;">
    <?php echo $row['modify_date']; ?>
    </td>  
    <td style="background-color:#F8D2F9;">
    <!--<img src="image/delete_icon.jpg" alt="Delete" onclick="alert('<?php //echo $row['type_id']; ?>');">-->   
    <img src="image/delete_icon.jpg" alt="delete" title="Delete" onclick="del('<?php echo $row['type_id']; ?>')">
    </td>  
</tr>   
<?php  
}
?>
</table>
</form>
<div style="margin-top:50px;">
<?php if($page_no!=1)
{ ?>
<a href="http://localhost/pagination_core_php?page_no=<?php echo $page_no-1;?>">Prev</a>
<?php }?>
<?php
for($i=1;$i<=$num_pages;$i++)
{
?>
<a href="http://localhost/pagination_core_php?page_no=<?php echo $i;?>" <?php if($i==$page_no) echo 'id="select_a"';?>><?php echo $i;?></a>

<?php
}
if($page_no!=$num_pages)
{
?>
<a href="http://localhost/pagination_core_php?page_no=<?php echo $page_no+1;?>">Next</a>
<?php
}?>
</div>
<?php
mysql_close($conn);
?>
</body>
</html>

No comments:

Post a Comment