Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Auto save data everytime click/choose the employee name

innerHTML

  • Please log in to reply
2 replies to this topic

#1 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 05 December 2011 - 05:05 PM

Hi,

Now, I save data to database using the save button with this code:
<?php
include 'config.php';

$currentEmpID = $_SESSION['empID'];
 
 
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav); 

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";     
    
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno); 

 //==============Save Other Earnings============//
 $RegOTAmt = $_POST['RegOTAmt'];
 $SunSpecHolAmt = $_POST['SunSpecHolAmt'];
 $SunSpecHolOtAmt = $_POST['SunSpecHolOtAmt'];
 $RegHolAmt = $_POST['RegHolAmt'];
 $RegHolOtAmt = $_POST['RegHolOtAmt'];
 $HolLeaveAmt = $_POST['HolLeaveAmt'];
 $NightPremAmt = $_POST['NightPremAmt'];
 $MealAllowAmt = $_POST['MealAllowAmt'];
 $COLAAmt = $_POST['COLAAmt'];
 
 $sql = "SELECT EMP_NO, OTReg_Amt, SunReg_Amt, OTSun_Amt, HolReg_Amt, HolRegOT_Amt, HolLeave_Amt, NP_Amt, Meal_Amt, Cola_Amt FROM other_earnings WHERE EMP_NO = '$empno'";
 $RsOtherEarnings = $conn2->Execute($sql);
 
 $numrowsOtherEarnings = $RsOtherEarnings->RecordCount();
 
 if($numrowsOtherEarnings > 0){ 
 
 $saverec['EMP_NO'] = $empno;
 $saverec['OTReg_Amt'] = $RegOTAmt;
 $saverec['SunReg_Amt'] = $SunSpecHolAmt;
 $saverec['OTSun_Amt'] = $SunSpecHolOtAmt;
 $saverec['HolReg_Amt'] = $RegHolAmt;
 $saverec['HolRegOT_Amt'] = $RegHolOtAmt;
 $saverec['HolLeave_Amt'] = $HolLeaveAmt;
 $saverec['NP_Amt'] = $NightPremAmt;
 $saverec['Meal_Amt'] = $MealAllowAmt;
 $saverec['Cola_Amt'] = $COLAAmt;
 
  $updateOtherEarnings = $conn2->GetUpdateSQL($RsOtherEarnings, $saverec); 
  $conn2->Execute($updateOtherEarnings); 
 }
 else{
 $sql = "SELECT o.EMP_NO, o.OTReg_Amt, o.SunReg_Amt, o.OTSun_Amt, o.HolReg_Amt, o.HolRegOT_Amt, o.HolLeave_Amt, o.NP_Amt, o.Meal_Amt, o.Cola_Amt FROM $PAYROLL.other_earnings o, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsOtherEarnings = $conn2->Execute($sql);
 
 $saverec['EMP_NO'] = $empno;
 $saverec['OTReg_Amt'] = $RegOTAmt;
 $saverec['SunReg_Amt'] = $SunSpecHolAmt;
 $saverec['OTSun_Amt'] = $SunSpecHolOtAmt;
 $saverec['HolReg_Amt'] = $RegHolAmt;
 $saverec['HolRegOT_Amt'] = $RegHolOtAmt;
 $saverec['HolLeave_Amt'] = $HolLeaveAmt;
 $saverec['NP_Amt'] = $NightPremAmt;
 $saverec['Meal_Amt'] = $MealAllowAmt;
 $saverec['Cola_Amt'] = $COLAAmt;
 
  $insertOtherEarnings = $conn2->GetInsertSQL($RsOtherEarnings, $saverec); 
  $conn2->Execute($insertOtherEarnings); 
 }
 $smarty->display('header.tpl');
 $smarty->display('left.tpl');
 $smarty->display('empPayrollData.tpl');
 $smarty->display('footer.tpl');
  
?>


But i need to do is everytime the employee name was click and i click another employee name the data was in the first employee that I click will save.

here is my code for displaying employee name:
left.tpl
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function searchemppay(queryString) {
    var ajaxRequest = remoteRequestObject();
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
            var result = ajaxRequest.responseText;
            document.getElementById('searchpayroll').innerHTML = result;
        } 
    }
    var url = "search.php?query=" + queryString; 
    ajaxRequest.open("GET", url, true);
    ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    ajaxRequest.send(null);

}

function changeEmployeePay(queryID) {
 
window.location = "SearchData.php?queryEmpID=" + queryID;
}
</script>
<title>Untitled</title>
</head>
<body>
<div id="Search">
<form>
<p class="serif"><b>Search Lastname:</b></p>
<input type="text" name="search_" size="20" onkeyup="searchemppay(this.value);">  
<div id="searchpayroll" style="overflow:auto; height:390px; width:auto; margin-left:2px" >
<hr />
<ul>
{section name=co_emp loop=$personalAll}
<li onclick="changeEmployeePay('{$personalAll[co_emp].EMP_ID}')">{$personalAll[co_emp].FULLNAME}</li>
<hr />
{sectionelse}
<li>No records found</li>
{/section}
</ul>
</div>
</form>
</div>
</body>
</html>

search.php
<?php
session_start();
include 'config.php';

$queryString = $_GET["query"];

if ($queryString == "" || $queryString == null) {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL 
        ORDER BY FULLNAME ASC";
}
else {
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL WHERE LNAME LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";
}

$recPersonalQuery = $conn->Execute($sql);
if (!$recPersonalQuery->BOF) {
    $recPersonalQuery->MoveFirst();
}

echo "<hr />";
echo "<ul>";
while (!$recPersonalQuery->EOF) {
    $empID   = $recPersonalQuery->fields["EMP_ID"]; 
    $empFullName = $recPersonalQuery->fields["FULLNAME"];

    echo "<li onclick=changeEmployeePay('$empID'); style= 'font-family:'Times New Roman',Times,serif; font-size:10%;'>$empFullName</li>";
    echo "<hr />";
    $recPersonalQuery->MoveNext();
} 
echo "</ul>";

$recPersonalQuery->Close();
exit();    
?>

SearchData.php
<?php
session_start();

$queryStr = trim($_GET["queryEmpID"]);

$_SESSION['empID'] = $queryStr; 

session_write_close();
header("Location:DisplayEmpPayroll.php");
exit();
?>

DisplayEmpPayroll.php
<?php
include 'config.php';
$currentEmpID = $_SESSION['empID']; 
 
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav);
// ========================================================================================================================
$EMP_NO = $_POST['EMP_NO'];

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";      
  
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno);
 
 $sql = "SELECT EMP_ID, RATE FROM wage WHERE EMP_ID = '$currentEmpID'";
 $rsWage = $conn->Execute($sql);
 
 $Rate      = $rsWage->fields['RATE'];    
 

 $sql = "SELECT EMP_ID,EMP_NO, STATUS FROM employment WHERE EMP_ID = '$currentEmpID'";
 $rsStatus = $conn->Execute($sql);
 
 $STATUS = $rsStatus->fields['STATUS'];
 $EMP_ID = $rsStatus->fields['EMP_ID'];
 
 if ($STATUS == 'Regular'){
 
 $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours FROM $ADODB_DB.wage w, $ADODB_DB.employment em, $PAYROLL.regular_sum_hours r WHERE em.EMP_NO = r.EMP_NO AND w.EMP_ID = '$currentEmpID' AND em.EMP_ID = '$currentEmpID' GROUP BY r.EMP_NO"; 
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2); 
 }
 elseif($STATUS == 'Casual'){
 
  $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, c.Casual_Hours FROM $ADODB_DB.wage w, $ADODB_DB.employment em, $PAYROLL.casual_hours c WHERE em.EMP_NO = c.EMP_NO AND w.EMP_ID = '$currentEmpID' AND em.EMP_ID = '$currentEmpID' GROUP BY c.EMP_NO"; 
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Casual_Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2);  
 }
 else{
     $Hours = ('00:00');
     $Amount = (0);
 }
  
  $smarty->assign('Rate', $Rate);
  $smarty->assign('Hours', $Hours);
  $smarty->assign('Amount', $Amount);
$smarty->display('header.tpl');
$smarty->display('left.tpl');
$smarty->display('empPayrollData.tpl');
$smarty->display('footer.tpl'); 


I don't know how can i insert my code in saving in choosing the employee name and then it will save data when i choose another employee name.

Any help is highly appreciated..

I attach the sample image of my webpage for further understanding.

Thank you so much

Attached Thumbnails

  • sample image1.JPG

Edited by newphpcoder, 05 December 2011 - 05:41 PM.

  • 0

#2 bbqroast

bbqroast

    Codecall Addict

  • Senior Member
  • PipPipPipPipPipPip
  • 564 posts
  • Location:/etc/passwd

Posted 07 December 2011 - 01:31 PM

AJAX?
  • 0
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#3 newphpcoder

newphpcoder

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 527 posts

Posted 07 December 2011 - 04:31 PM

How????


Thank you
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download