|
|
|
รบกวนหน่อยค่ะ อยากได้โค้ดคำนวณดอกเบี้ยเงินกู้ลง Database (ฐานข้อมูล) |
|
|
|
|
|
|
|
Code (PHP)
<?php require_once('../Connections/connection.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO loans (Loans_id, Loans_date, Members_name, Loans_money, Loans_interest, Loans_balance, Loans_deadline, Loans_status) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Loans_id'], "text"),
GetSQLValueString($_POST['Loans_date'], "date"),
GetSQLValueString($_POST['Members_name'], "text"),
GetSQLValueString($_POST['Loans_money'], "int"),
GetSQLValueString($_POST['Loans_interest'], "int"),
GetSQLValueString($_POST['Loans_balance'], "int"),
GetSQLValueString($_POST['Loans_deadline'], "date"),
GetSQLValueString($_POST['Loans_status'], "text"));
mysql_select_db($database_connection, $connection);
$Result1 = mysql_query($insertSQL, $connection) or die(mysql_error());
$insertGoTo = "loans_insert.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
$colname_loans_insert = "-1";
if (isset($_GET['Loans_id'])) {
$colname_loans_insert = $_GET['Loans_id'];
}
mysql_select_db($database_connection, $connection);
$query_loans_insert = sprintf("SELECT * FROM loans WHERE Loans_id = %s", GetSQLValueString($colname_loans_insert, "text"));
$loans_insert = mysql_query($query_loans_insert, $connection) or die(mysql_error());
$row_loans_insert = mysql_fetch_assoc($loans_insert);
$totalRows_loans_insert = mysql_num_rows($loans_insert);
mysql_select_db($database_connection, $connection);
$query_Member = "SELECT Members_name FROM members";
$Member = mysql_query($query_Member, $connection) or die(mysql_error());
$row_Member = mysql_fetch_assoc($Member);
$totalRows_Member = mysql_num_rows($Member);
?>
<!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>ศูนย์ข้าวชุมชนตำบลโพกรวม</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="614" align="center">
<tr valign="baseline">
<td colspan="3" align="center" nowrap="nowrap">ข้อมูลการกู้ยืมทุนกองทุน</td>
</tr>
<tr valign="baseline">
<td colspan="3" align="center" nowrap="nowrap"><p align="center">อัตราดอกเบี้ย>>ร้อยละ 1 บาทต่อเดือน</p></td>
</tr>
<tr valign="baseline">
<td width="140" align="right" nowrap="nowrap">เลขที่สัญญา :</td>
<td colspan="2"><input type="text" name="Loans_id" value="" size="10" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">วงเงินกู้ :</td>
<td colspan="2"><input name="Loans_money" type="text" value="" size="10" />
( ไม่เกิน 5,000 บาท ต่อคน )</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ชื่อสมาชิกศูนย์ข้าว :</td>
<td colspan="2"><label for="Members_name"></label> <label for="Members_name"></label>
<select name="Members_name" id="Members_name">
<?php
do {
?>
<option value="<?php echo $row_Member['Members_name']?>"><?php echo $row_Member['Members_name']?></option>
<?php
} while ($row_Member = mysql_fetch_assoc($Member));
$rows = mysql_num_rows($Member);
if($rows > 0) {
mysql_data_seek($Member, 0);
$row_Member = mysql_fetch_assoc($Member);
}
?>
</select> <label for="Member_name"></label></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">วันทำสัญญา :</td>
<td width="70"><input name="Loans_date" type="text" value="<?
$date = date("d-m-Y");
echo $date;
?>" size="10" /></td>
<td width="416">
กำหนดคืน:
<input type="text" name="Loans_deadline" value="" size="10" /> (สิ้นสุดสัญญา 6 เดือน)</td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">สถานกู้ยืม :</td>
<td colspan="2"><select name="Loans_status" id="Loans_status" title="<?php echo $row_loans_insert['Loans_status']; ?>" >
<option value="ยังไม่ได้ชำระเงิน">ยังไม่ได้ชำระเงิน</option>
<option value="ชำระเงินแล้ว">ชำระเงินแล้ว</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td colspan="2"><input type="submit" value="เพิ่มข้อมูล" /></td>
</tr>
</table>
<table width="700" border="0" align="center">
<tr>
<td align="right"><a href="admin_page.php">กลับเมนูหลัก</a></td>
</tr>
</table>
<table border="1" align="center">
<tr align="center">
<td>เลขที่สัญญา</td>
<td>วันทำสัญญา</td>
<td>ชื่อ - นามสกุลสมาชิก</td>
<td>วงเงินกู้</td>
<td>ดอกเบี้ย</td>
<td>จำนวนเงินคืน</td>
<td>กำหนดคืน</td>
<td>สถานะกู้ยืม</td>
</tr>
<?php do { ?>
<tr align="center">
<td><?php echo $row_loans_insert['Loans_id']; ?></td>
<td><?php echo $row_loans_insert['Loans_date']; ?></td>
<td><?php echo $row_loans_insert['Members_name']; ?></td>
<td><?php echo $row_loans_insert['Loans_money']; ?></td>
<td><?php echo $row_loans_insert['Loans_interest']; ?></td>
<td><?php echo $row_loans_insert['Loans_balance']; ?></td>
<td><?php echo $row_loans_insert['Loans_deadline']; ?></td>
<td><?php echo $row_loans_insert['Loans_status']; ?></td>
</tr>
<?php } while ($row_loans_insert = mysql_fetch_assoc($loans_insert)); ?>
</table>
<p>
<input type="hidden" name="MM_insert" value="form1" />
</p>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($loans_insert);
mysql_free_result($Member);
?>
ผลลัพธ์
พอใส่ข้อมูลทั้งหมดแร้ว ตรง "วงเงินกู้" มันจะคำนวณดอกเบี้ยและจำนวนเงินคืนอัตโนมัติและมาแสดงข้อมูล ตรงคอลัมน์ข้างล่างอะค่ะ
Tag : PHP, MySQL, HTML/CSS, Web (ASP.NET), WebService, Web Service
|
|
|
|
|
|
Date :
2015-10-17 22:01:50 |
By :
monchusa |
View :
2127 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาตัวแปรที่เกี่ยวข้อง ที่ต้องการมาลิสต์เป็นรายการ เขียนใส่ กระดาษ
ต้วอย่าง
เงินต้น =$_POST['cost']
เงินต่องวด = $_POST['permonth'];
แล้วใส่สูตรเข้าไป เขียนใน กระดาษ
แล้วค่อยมาแปลงเขียนในโปรแกรม
flowchart flowcontrol เล็กๆ จะทำให้เขียนโปรแกรมง่ายขึ้น
|
|
|
|
|
Date :
2015-10-18 08:15:07 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|