Wednesday, May 16, 2012

Payment Calculation Completed

Alhamdulillah... siap juga sql code utk payment calculation ni...

codes untuk calculate items tak susah...

yang susahnya, code untuk retrieve data from table and update data in table...

kalau direct retrieve and update, boleh guna the readymade Dreamweaver Recordset and Insert Record..

tapi bila dia berkait2 dengan data from different tables.. kenala modify the coding.

finally... the codes that cheers my day..

$_POST and $_GET

URL parameters in the Run-time Value column:

Server Model
Run-Time value expression for URL parameter
ASP Request.QueryString(“formFieldName”)
PHP$_GET['formFieldName']



Form parameters in the Run-time Value column:

Server Model
Run-Time value expression for form parameter
ASP Request.Form(“formFieldName”)
PHP$_POST['formFieldName']


Example of calculatoin codes
****************************
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {


$pibg = $_POST['pibg'];
$selenggara = $_POST['selenggara'];
$lkerja = $_POST['lkerja'];
$majalah = $_POST['majalah'];
$diari = $_POST['diari'];
$progismor = $_POST['progismor'];
$yurankelas = $_POST['yurankelas'];
$progakadmk = $_POST['progakadmk'];
$total=134;
$totalpaid = $pibg+$selenggara+$lkerja+$majalah+$diari+$progismor+$yurankelas+$progakadmk;
$totalunpaid=$total-$totalpaid;

$updateSQL = sprintf("UPDATE student SET name=%s, `class`=%s, dadic=%s, dadname=%s, momic=%s, momname=%s, guidic=%s, guidname=%s, tel=%s, adress=%s, pibg=%s, selenggara=%s, lkerja=%s, majalah=%s, diari=%s, progismor=%s, yurankelas=%s, progakadmk=%s, totalpaid=%s, totalunpaid=%s WHERE ic=%s",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['class'], "text"),
                       GetSQLValueString($_POST['dadic'], "int"),
                       GetSQLValueString($_POST['dadname'], "text"),
                       GetSQLValueString($_POST['momic'], "int"),
                       GetSQLValueString($_POST['momname'], "text"),
                       GetSQLValueString($_POST['guidic'], "int"),
                       GetSQLValueString($_POST['guidname'], "text"),
                       GetSQLValueString($_POST['tel'], "int"),
                       GetSQLValueString($_POST['adress'], "text"),
                       GetSQLValueString($_POST['pibg'], "double"),
                       GetSQLValueString($_POST['selenggara'], "double"),
                       GetSQLValueString($_POST['lkerja'], "double"),
                       GetSQLValueString($_POST['majalah'], "double"),
                       GetSQLValueString($_POST['diari'], "double"),
                       GetSQLValueString($_POST['progismor'], "double"),
                       GetSQLValueString($_POST['yurankelas'], "double"),
                       GetSQLValueString($_POST['progakadmk'], "double"),
                       $totalpaid,
        $totalunpaid, 
                       GetSQLValueString($_POST['ic'], "text"));
Example of finding a particular list of data
********************************************

// find the ic of the teacher
$colname_Recordset0 = "-1";
if (isset($_SESSION['username'])) {
  $colname_Recordset0 = $_SESSION['username'];
}
mysql_select_db($database_feesconn, $feesconn);
$query_Recordset0 = sprintf("SELECT * FROM `user` WHERE username = %s", GetSQLValueString($colname_Recordset0, "text"));
$Recordset0 = mysql_query($query_Recordset0, $feesconn) or die(mysql_error());
$row_Recordset0 = mysql_fetch_assoc($Recordset0);
$totalRows_Recordset0 = mysql_num_rows($Recordset0);

// assign a session variable
$_SESSION['ic'] = $row_Recordset0['ic'];

// find the class of the teacher
$colname_Recordset2 = "-1";
if (isset($_SESSION['ic'])) {
  $colname_Recordset2 = $_SESSION['ic'];
}
mysql_select_db($database_feesconn, $feesconn);
$query_Recordset2 = sprintf("SELECT * FROM teacher WHERE ic = %s", GetSQLValueString($colname_Recordset2, "text"));
$Recordset2 = mysql_query($query_Recordset2, $feesconn) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);
$_SESSION['class']=$row_Recordset2['class'];

// start finding students in class
$colname_Recordset1 = "-1";
if (isset($_SESSION['class'])) {
  $colname_Recordset1 = $_SESSION['class'];
}
mysql_select_db($database_feesconn, $feesconn);
$query_Recordset1 = sprintf("SELECT * FROM student WHERE `class` = %s ORDER BY name ASC", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $feesconn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 

No comments:

Post a Comment