hi evryone...
i have two tables first one is takeleave and the second one is leave...and when any employee
take leave by filling the leave form then according to the no. of days leave taken the value should be deducted from
another table i.e leave table.
but m unable to understand how to do it.....plz hlp me out......
table structure of leave table-----------
CREATE TABLE leave (
ecode varchar(15) NOT NULL default '',
CL int(5) NOT NULL default '0',
ML int(5) NOT NULL default '0',
EL int(5) NOT NULL default '0',
clv_days int(5) NOT NULL default '0',
mlv_days int(5) NOT NULL default '0',
elv_days int(5) NOT NULL default '0'
) TYPE=MyISAM;

table structu of takeleave table------
CREATE TABLE takeleave (
ecode varchar(15) NOT NULL default '',
leavetype varchar(15) NOT NULL default '',
des varchar(20) NOT NULL default '',
lv_from date NOT NULL default '0000-00-00',
lv_to date NOT NULL default '0000-00-00',
lv_days int(5) NOT NULL default '0'
) TYPE=MyISAM;

<html>
<body bgcolor="E6E6FA">
<?
mysql_connect("localhost","root","root");
mysql_select_db("master");
$ecode=$_POST['ecode'];
$CL=$_POST['CL'];
$ML=$_POST['ML'];
$EL=$_POST['EL'];
$clv_days=$_POST['clv_days'];
$mlv_days=$_POST['mlv_days'];
$elv_days=$_POST['elv_days'];
$leav="select leavetype from leave";
if($leav=='CL')
{
mysql_query("UPDATE leave SET CL = CL -clv_days;");
}
$result=mysql_query("select ecode,CL,ML,EL from leave");

echo "<table border='3'><BR><BR><BR><BR>
<tr>
<th >Code</th>
<th>CL</th>
<th>ML</th>
<th>EL </th>
</tr>"  ;

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ecode'] . "</td>";
echo "<td>" . $row['CL'] . "</td>";
echo "<td>" . $row['ML'] . "</td>";
echo "<td>" . $row['EL'] . "</td>";
echo "</tr>";
}
mysql_close();
?>
</body>
</html>
<HTML>
<HEAD>
<TITLE>New Document</TITLE>
</HEAD>
<BODY>
<?php
$ecode = $_POST["ecode"];
$leavetype= $_POST["leavetype"];
$des =$_POST["des"];
 $lv_from=$_POST["lv_from"];
$lv_to=$_POST["lv_to"];
$lv_days=$_POST["lv_days"];
//$left=$_POST["asubdpt"];
  mysql_connect("localhost","root","root");
  mysql_select_db("master");
 $query="INSERT INTO Takeleave VALUES  ('$ecode','$leavetype','$des','$lv_from','$lv_to','$lv_days')";
   if (mysql_query($query))

   {
echo "record added!";
include("displayleaves.php");
}
else
{
echo "something went wrong";
}
mysql_close();
?>
</BODY>
</HTML>
<HTML>
<HEAD>
 <TITLE>New Document</TITLE>
  <script type="text/javascript">
function validate_form ( )
{
valid = true;
if ( document.myform.ecode.value == "" )
 {
 alert ( "Please fill in the 'Code' box." );
  myform.ecode.focus();
 valid = false;
return valid;
}
if ( document.myform.lt.value == "" )
 {
 alert ( "Please select the leave type" );
  myform.lt.focus();
 valid = false;
return valid;
}
if ( document.myform.des.value == "" )
 {
 alert ( "Please fill in the Description box." );
  myform.des.focus();
 valid = false;
return valid;
}
if ( document.myform.lv_from.value == "" )
 {
 alert ( "Please enter the starting dat of leave" );
  myform.lv_from.focus();
 valid = false;
return valid;
}
if ( document.myform.lv_to.value == "" )
 {
 alert ( "Please enter the ending date of leave" );
  myform.lv_to.focus();
 valid = false;
return valid;
}
</script>
</HEAD>
<BODY bgcolor="E6E6FA"  onLoad="myform.ecode.focus()";>
<form action="emplvins.php" method="POST" name="myform" onsubmit="return validate_form();">
<h2> <p align="center"> Leave Form </p></h2>
<table align="center">  <tr> <th>  Employee Code: </th>
<td> <input type="text" size="20" name="ecode" value=""></td> </tr>
<tr> <th> &nbsp;&nbsp;&nbsp;&nbsp; Leave Type: </th>
<td><select size="1" name="leavetype">
   <option>---Select---</option>
   <option>Casual Leave</option>
   <option>Earned Leave</option>
   <option>Medical Leave</option>
</select>  </td></tr>
&nbsp;&nbsp;&nbsp;
<tr><th> &nbsp;&nbsp;&nbsp;&nbsp;Description:</th>
<td><textarea name="des" size="20" value=""></textarea>
<tr> <th> &nbsp;&nbsp;&nbsp;&nbsp;Leave From: </th>
<td> <input type="text" size="20" name="lv_from" value=""> yyyy-mm-dd</td> </tr>
<tr> <th> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Leave To: </th>
<td> <input type="text" size="20" name="lv_to"  value=""> yyyy-mm-dd</td>  </tr>
<tr> <th> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Leave Days: </th>
<td> <input type="text" size="20" name="lv_days"  value=""></td>  </tr>
<td> <td> <input type="submit" value="Submit"> </td>
 </table>
 </form>
</BODY>
</HTML>

Recommended Answers

All 7 Replies

$update_query = "UPDATE leave SET CL = CL - $clv_days where ecode=$ecode";

i think m not on the right track....can u hlp me out.if m using correct logic for left leaves of employees after taking leaves from another table...

In the table "leave" lets assume that you are using the field this way

CL int(5) -----> To store the alloted CL's by the company
ML int(5) -----> To store the alloted ML's by the company
EL int(5) -----> To store the alloted ML's by the company
clv_days int(5) -----> To store the available CL's for an employee
mlv_days int(5) -----> To store the available ML's for an employee
elv_days int(5) -----> To store the available EL's for an employee

Now after you do the insert successfully, you can do the update there itself

$query="INSERT INTO Takeleave VALUES  ('$ecode','$leavetype','$des','$lv_from','$lv_to','$lv_days')";
if (mysql_query($query)) {
$update_coloumn = ($leavetype == "CL") ? "CL" : (($leavetype == "ML") ? "ML" : "EL");
$update_query = "UPDATE leave SET ".$update_coloumn." = ".($update_coloumn - $lv_days)." where ecode=$ecode";
//mysql_query($update_query);
}

hi...
i have table i.e leave_master in which i hve assigned leaves to all the employess of the company once.
now i have one another table i,e takeleave in which employyee fill the form to take leave
and that info. will store in the takeleave table.
and the third table is leave in which i want when any employee take the leave,according to the no.
of days leave taken the table should be automatically updated based on "takeleave" table field i.e lv_days.
through leave table i want that employee should be able to know how many leaves are left to him from total leavs.
so this is what i want..
hope you'll understand nd hlp me out.
table structure of leave_master table is------------
CREATE TABLE leave_master (
ecode varchar(15) NOT NULL default '',
CL int(10) NOT NULL default '0',
ML int(10) NOT NULL default '0',
EL int(10) NOT NULL default '0'
) TYPE=MyISAM;

still waiting for the reply.............

CREATE TABLE leave (
ecode varchar(15) NOT NULL default '',
CL int(5) NOT NULL default '0',
ML int(5) NOT NULL default '0',
EL int(5) NOT NULL default '0',
clv_days int(5) NOT NULL default '0',
mlv_days int(5) NOT NULL default '0',
elv_days int(5) NOT NULL default '0'
) TYPE=MyISAM;


can you please explain the fields in the above table that you had posted earlier ?

I do have the clear idea on what 'leave_master' and 'takeleave' are meant for. So please give me the correct structure and description of the table 'leave'

Casual leave field first time
display alotted leaves to emp
Medical,earned work same as casual
.. now CL left leaves shown in
casual leave field
medial left leave shown in ML field
earned left leave shown in EL "
lv_days that is for how many days any emp
taken the leave..
From the take leave form
emp will fill d form and
where he/she specify d type of leave
dat is decided which leave emp taken
according to dat employee 's leaves will left

i m greatly thankful to you for taking time to solve my prob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.