确定期间内交易记录的值

时间:2015-11-27 12:07:05

标签: php mysqli

我有一张表格可以记录客户的日常交易。但是,如果客户是第一次付款,则应将其标记为1,无论是在月份的开头,中间还是最后一天。有任何想法来解决这个问题。以下是我的试用版。当它是新客户但不是已在数据库中拥有交易的现有客户时,它可以工作。

    <?php
    if(isset($_POST["save"])){
    $custid = $_POST["custid"];
    $transDate = $_POST["transDate"];
    $grpid = $_POST["custgrp"];
    $amount = $_POST["amount"];
    $postedBy = $_SESSION["staffid"];
    $postStatus= $_POST["postStatus"];
//check if today is first day of the month.if yes, set to 1
    $dF = strtotime($transDate); 
    $rStatus = date("d",$dF);
    if($rStatus==1){
    $rStatus = 1; }else{ $rStatus = 0;} 
//check if the customer has record at all. if yes set the counter to 1 otherwise increase the counter
    $getRole = $connection->query("SELECT * FROM tab_customer_dailycontribution WHERE custid ='$custid'");
    $count = mysqli_num_rows($getRole);

    if($count>=0){
        $count = $count+1;

    $insert = mysqli_query($connection,"INSERT INTO tab_customer_dailycontribution(custid,grpid,amountContribute,transactionDate,counter,rstatus,postedBy,postStatus)VALUES(
              '$custid','$grpid','$amount','$transDate','$count','$rStatus','$postedBy','$postStatus')");

    if($insert){
    echo "<span style='font-weight:bold;color:red;>'"." Transaction is Successful!"."</span>";  

    }else{
    //Unable to save    
    echo "<span style='font-weight:bold;color:black;>'"."Error! Transaction not Successful!"."</span>"; 
    }   
    }//end if count
        //}//end if for checking if today is 1
    }else{
    $custid = "";
    $transDate = "";
    $grpid = "";
    $amount = "";
    $postedBy = ""; 
    }
    ?>

0 个答案:

没有答案