Php 在一段时间内从交易记录中确定一个值
我有一个表格可以记录客户的日常交易。但是,如果客户是第一次付款,则无论是在月初、月中还是月底,都应将其标记为1。是否有解决此问题的方法。下面是我的试用版。当它是一个新客户,而不是数据库中已经有交易的现有客户时,它会起作用Php 在一段时间内从交易记录中确定一个值,php,mysqli,Php,Mysqli,我有一个表格可以记录客户的日常交易。但是,如果客户是第一次付款,则无论是在月初、月中还是月底,都应将其标记为1。是否有解决此问题的方法。下面是我的试用版。当它是一个新客户,而不是数据库中已经有交易的现有客户时,它会起作用 <?php if(isset($_POST["save"])){ $custid = $_POST["custid"]; $transDate = $_POST["transDate"]; $grpid = $_POST["cust
<?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 = "";
}
?>
仅在$count>0时使用{@Saty:如果我使用$count>0,对于数据库中没有任何以前记录的新用户会发生什么?而且,我也尝试过,它也不起作用。