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>

Simple Login HTML page with Javascript validation

<!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>Dalal System</title>
<script type="text/javascript" src="js/jquery1_3.js"></script>
<script type="text/javascript">
    function check_validation()
    {
        var username=document.getElementById("username").value;
        var password=document.getElementById("password").value;
        //alert(username);
        if(username == "" || password == "")
        {
            alert("Please fill the username and password");
            $('#username').focus();
            return false;
            //document.getElementById("username").focus();
        }
    }
</script>
</head>

<body>
    <fieldset style="width:23%; position:relative; margin-top:19%; margin-left:40%"><legend>LogIn</legend>
    <form name="login_form" id="login_form" method="post" onsubmit="return check_validation()">
    <div align="center">
        <table border=0>
            <tr>
                <td>
                    Username:   
                </td>
                <td>
                    <input type="text" name="username" id="username" placeholder="Username" />
                </td>
            </tr>
            <tr>
                <td>
                    Password:   
                </td>
                <td>
                    <input type="password" name="password" id="password" placeholder="Password" onpaste="alert('Copy and Paste are strictly prohibited on Password'); return false;" oncopy="alert('Copy and Paste are strictly prohibited on Password'); return false;"/>
                </td>
            </tr>
            <tr align="center">
                <td colspan="2">
                    <input type="submit" value="LogIn" name="login" id="login" />
                    <input type="reset" value="Cancel">
                 </td>
            </tr>
        </table>
    </div>
    </form>
    </fieldset>
 
</body>
</html>

img tag tooltip text

Sometime we use img tag for put icon in html page at that time we can put tooltip text using title attrbute of img tag.

example.:
<img src="image/delete_icon.jpg" alt="delete" title="Delete" onclick="del('<?php echo $row['type_id']; ?>')">

Ajax call using Jquery

        $.ajax({
            type: "POST",
            url: "d.php",
            //data: data,
            //dataType: "JSON",
            success: function(){
                alert("success");
            }
         });
Passing id as post
$.ajax({
            type: "POST",
            url: "d.php",
            data: {id:id},
            //dataType: "JSON",
            success: function(msg){
                alert(msg);
            }
         });

Friday, May 24, 2013

program to implement else if command



Aim: Write a program to implement else if command.
Program:

#include<stdio.h>
int main(int argc, char *argv[])
{
          int fd;
          char c;
          if(arg!=2)
          {
                   printf(“ERROR”);
                    fd=open(argv[1],O_RDONLY);
                   while((sk=READ(fd,&c,1))==1)
          }
          printf(“%c”,&c);
          sk=lseek(fd,1000,0)
          printf(“New seek value = %d”,sk);
}
}
Output:
cc seek.c
./a.out seek.c
#new seek value 1000

program to create a new process using fork system call

Aim: Write a program to create a new process using fork system call.

Program:

#include<stdio.h>
#include<fcntl.h>
int main(void)
{
          int fd;
          fd=getpid();
          if(fork()<0)
          {
                   printf(“\n Child is not created.”);
          }
          else
          {
                   printf(“\n Child is created.”);
          }
}

program to copy a file



Aim: Write a program to copy a file.
Program:

#include<stdio.h>
#include<fcntl.h>
#define buf 2048
int main(int argc, char *argv[])
{
          int fd,fd1;
          char buf1[buf];
          fd=open(argv[1],O_RDWR);
read(fd,buf1,buf);
fd1=creat(argv[2],O_WRONLY);
          write(fd1,buf1,buf);
close(fd);
close(fd1);
}

Output:
$ cat aa.txt
HELLO
$ cc copy.c
$ ./a.out aa.txt a.txt
$ cat a.txt
HELLO

program for cat command



Aim: Write a program for cat command.
Program:

#include<stdio.h>
#include<fcntl.h>
#define buf 2048
int main(int argc, char *argv[])
{
          int fd;
          char buf1[buf];
          fd=open(argv[1],O_RDWR);
          read(fd,buf1,buf);
          printf(“%s”,buf1);
}

Output:
$ cc cat.c
$ ./a.out cat.txt