  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                <? session_start(); ?> 
<?php require_once('Connections/TTCon.php'); ?> 
<?php 
    foreach($_POST as $key=>$value){ 
        $$key=$value; 
    } 
    foreach($_GET as $key=>$value){ 
        $$key=$value; 
    } 
?> 
 
<?php 
 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
{ 
  $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; 
} 
} 
 
$s1=$_SESSION['ssd']; 
mysql_select_db($database_TTCon, $TTCon); 
$query_Recordset1 = "SELECT billmoney.BID, billmoney.Bpaid,  customer.CusName, zonemoney.ZmName, customer.ZmID, billmoney.BMoney, billmoney.BillStID FROM billmoney, customer, zonemoney WHERE billmoney.CusID = customer.CusID AND customer.ZmID = zonemoney.ZmID AND customer.ZmID='$s1' AND billmoney.BillStID <> '104' GROUP BY billmoney.BID"; 
$Recordset1 = mysql_query($query_Recordset1, $TTCon) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 
 
//echo $totalRows_Recordset1; 
//exit(); 
 
 
 
?> 
 
<!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"> 
<!-- 
.style2 { 
	font-family: Tahoma, "MS Sans Serif", "Angsana New", AngsanaUPC; 
	font-weight: bold; 
} 
.style4 {color: #000000} 
.style7 {font-family: Tahoma, "MS Sans Serif", "Angsana New", AngsanaUPC} 
.style9 {color: #0000FF; font-family: Tahoma, "MS Sans Serif", "Angsana New", AngsanaUPC; } 
.style11 {font-size: 12px} 
.style15 {font-family: Tahoma, "MS Sans Serif", "Angsana New", AngsanaUPC; font-size: 12px; } 
.style16 { 
	font-size: 14px 
} 
.style17 {font-size: 16px} 
.style19 {color: #FF0000; font-family: Tahoma, "MS Sans Serif", "Angsana New", AngsanaUPC; } 
.style21 {font-size: 16px; color: #28A745; } 
.style22 {font-size: 14} 
--> 
</style> 
</head> 
 
<body> 
<p> 
 
  <? 
 
	 
	 $y =date(Y); 
	$m =date(m); 
	$d =date(d); 
	 $dmy=$y."-".$m."-".$d; 
	 
	for($i=0;$i<$totalRows_Recordset1;$i++) 
	{ 
	$cd=$_POST["hidd"][$i];//จ่ายงวดที่เท่าไร 
	$aa=$_POST["txtc"][$i];//จำนวนเงินที่จ่ายต่องวด 
	$ad=$_POST["hid"][$i];//รหัสใบจ่ายหลัก 
	$pd=$_POST["Bpa"][$i]+$aa; //ยอดจ่ายสะสม 
 
			mysql_select_db($database_TTCon, $TTCon); 
			$query_Recordset3 = "SELECT billdetail.BID, billdetail.BcID FROM billdetail WHERE billdetail.BID='$ad' AND billdetail.BcID ='$cd' ORDER BY  billdetail.BcID DESC"; 
			$Recordset3 = mysql_query($query_Recordset3, $TTCon) or die(mysql_error()); 
			$row_Recordset3 = mysql_fetch_assoc($Recordset3); 
			$totalRows_Recordset3 = mysql_num_rows($Recordset3); 
	//echo "ลำดับที่".$i."|"."เลขที่บิล".$ad."|"."'งวดที่".$cd."|"."จำนวนเงิน".$aa."<br>"; 
	 
 
			if ($totalRows_Recordset3==0) { 
			//Update ตารางหลักที่ Bpaid จ่ายสะสมมากี่งวดเป็นเงินกี่บาท 
		mysql_select_db($database_TTCon, $TTCon); 
		$query_Recordset4 = "UPDATE  `billmoney` SET  `Bpaid` =  '$pd' WHERE CONVERT(  `billmoney`.`BiD` USING utf8 ) =  '$ad' "; 
		mysql_query($query_Recordset4, $TTCon) or die(mysql_error()); 
 
 
			//เพิ่มข้อมูลการจ่ายเงินในตารางรายละเอียด 
			$cd=1; 
			mysql_select_db($database_TTCon, $TTCon); 
			$query_Recordset2 = "INSERT INTO `billdetail` (`BID` ,`BcID` ,`BcountPaid` ,`BmoneyIn` ,`BdateMoney` )VALUES ('$ad', '$cd',  '$cd',  '$aa',  '$ttdate')"; 
			mysql_query($query_Recordset2, $TTCon) or die(mysql_error()); 
		}else{ 
					//Update ตารางหลักที่ Bpaid จ่ายสะสมมากี่งวดเป็นเงินกี่บาท 
		mysql_select_db($database_TTCon, $TTCon); 
		$query_Recordset4 = "UPDATE  `billmoney` SET  `Bpaid` =  '$pd' WHERE CONVERT(  `billmoney`.`BiD` USING utf8 ) =  '$ad' "; 
		mysql_query($query_Recordset4, $TTCon) or die(mysql_error()); 
 
 
					//เพิ่มข้อมูลการจ่ายเงินในตารางรายละเอียด 
			$cd=$cd+1; 
			mysql_select_db($database_TTCon, $TTCon); 
			$query_Recordset2 = "INSERT INTO `billdetail` (`BID` ,`BcID` ,`BcountPaid` ,`BmoneyIn` ,`BdateMoney` )VALUES ('$ad', '$cd', '$cd', '$aa',  '$ttdate')"; 
			mysql_query($query_Recordset2, $TTCon) or die(mysql_error()); 
 
 
 
 
		}  
 
 
 
	} 
 
 
 
?> 
  <?php 
//เรียกดูข้อมูลว่า ค่าเอกสารมีหรือไม่ถ้าไม่มีเพิ่มไป ถ้า มีบวกเพิ่ม 
mysql_select_db($database_TTCon, $TTCon); 
$query_Recordset11 = "SELECT pay_money.Pdoc, pay_money.ID_Pay, pay_money.ZmID FROM pay_money WHERE pay_money.ZmID='$hz' AND pay_money.DatePay='$ttdate' "; 
$Recordset11 = mysql_query($query_Recordset11, $TTCon) or die(mysql_error()); 
$row_Recordset11 = mysql_fetch_assoc($Recordset11); 
$totalRows_Recordset11 = mysql_num_rows($Recordset11); 
if($totalRows_Recordset11==0){ 
 
			mysql_select_db($database_TTCon, $TTCon); 
$query_Recordset12 = "SELECT pay_money.ID_Pay, pay_money.Pdoc FROM pay_money ORDER BY ABS(pay_money.ID_Pay) DESC"; 
$Recordset12 = mysql_query($query_Recordset12, $TTCon) or die(mysql_error()); 
$row_Recordset12 = mysql_fetch_assoc($Recordset12); 
$totalRows_Recordset12 = mysql_num_rows($Recordset12); 
			if($totalRows_Recordset12==0){ 
			$Asd='1001'; 
			}else{ 
			$Asd=$row_Recordset12['ID_Pay']+1; 
			} 
 
				//อัพเดทค่าใช้จ่ายกรณีที่ไม่มีค่าใช้จ่ายเดิม 
			mysql_select_db($database_TTCon, $TTCon); 
			$query_Recordset2 = "INSERT INTO  `pay_money` (`ID_Pay` ,`ZmID` ,`DatePay` ,`Phome` ,`Pcome` ,`Poli` ,`Prepair` ,`Pfood` ,`Pdoc` ,`Pcut`,`PnewBill`,`Pother`)VALUES ('$Asd',  '$hz',  '$ttdate',  '$p3',  '$sumprice',  '$p4',  '$p5',  '$p6',  '$p7', '$p9', '$p10', '$p8')"; 
			mysql_query($query_Recordset2, $TTCon) or die(mysql_error()); 
}else{ 
		 
 
} 
 
 
 
 
 
 
 
?> 
</body> 
<center>เพิ่มข้อมูลเรียบร้อยแล้ว....กรุณารอสักครู่</center><br>  
<meta http-equiv='refresh' content='2;URL=PayIndex_Bill.php'> 
</html> 
<?php 
mysql_free_result($Recordset1); 
 
 
mysql_free_result($Recordset3); 
 
//mysql_free_result($Recordset12); 
 
//mysql_free_result($RecordsetPay); 
?> 
 
 
 
รูปแสดงผล ครับ 
  
 
 
คือ มันวนไปแล้ว อยู่ดีๆ ค่าที่มีอยู่ก็หายไป แก้ไม่ถูกครับ ไม่รู้เกิดจากอะไร สาขา มี 9 สาขา เป็นอยู่สาขาเดียว ซึ่งสาขานี้มีสมาชิกมากที่สุด รบกวนผู้รู้ทุกท่านด้วยครัย
 
 
  Tag : PHP, MySQL, Appserv, Windows               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2019-03-05 20:51:32 | 
                      By :
                          ping2009 | 
                      View :
                          604 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |