字段is_add(tinyint(1)),行不显示

时间:2015-11-04 08:17:22

标签: php mysql

我的代码出了什么问题?由于sizeof(int*),行不会显示。但当我将其更改为$is_add时,行显示且is_add的值为1

$tot_shrs_amt

我认为这是问题所在。

case "Compute":
    $is_add = $tot_shrs_amt.$bnfts.$dvdnd.$loan.$grcery.$life_insrnce.$funeral_pln.$flu_vccne.$eye_glss;

    $tot_shrs_amt  = $_POST['total_shares_amount'];
    $bnfts         = $_POST['benefits'];
    $dvdnd         = $_POST['dividend'];
    $coop_shrs     = $_POST['coop_shares'];
    $loan          = $_POST['loan']; 
    $grcery        = $_POST['grocery'];
    $life_insrnce  = $_POST['life_insurance'];
    $funeral_pln   = $_POST['funeral_plan'];
    $flu_vccne     = $_POST['flu_vaccine'];
    $eye_glss      = $_POST['eye_glass'];
    $tot_ddctns    = $_POST['total_deductions'];

    if($tot_shrs_amt){
        $tot_shrs_amt  = 1;
    }
    if($bnfts){
        $bnfts         = 1; 
    }
    if($dvdnd){
        $dvdnd         = 1;
    }
    if($coop_shrs){
        $coop_shrs     = 1;
    }
    if($loan){
        $loan          = 0;
    }
    if($grcery){
        $grcery        = 0;
    }
    if($life_insrnce){
        $life_insrnce  = 0;
    }
    if($funeral_pln){
        $funeral_pln   = 0;
    }
    if($flu_vccne){
        $flu_vccne     = 0;
    }
    if($eye_glss){
        $eye_glss      = 0;
    }
    if($tot_ddctns){
        $tot_ddctns    = 0;
    }

    $coopmemID = $_POST['coopmemID'];
    $emp_no = trim($_POST['emp_no']);
    $coop_shares = $_POST['total_share'];
    $total_deductions = $_POST['total_deductions'];
    $net_amount = $_POST['net_amount'];
    $date_resigned = $_POST['date_resigned'];
    $rep1 = str_replace(",", "", $coop_shares);
    $rep2 = str_replace(",", "", $total_deductions);
    $rep3 = str_replace(",", "", $net_amount);
    $sql = "INSERT INTO tb_finalpay (coopmemID, emp_no, total_share, total_deduct, net_amount, date_released, date_resigned) VALUES ('$coopmemID','$emp_no','$rep1','$rep2','$rep3','".date('Y-m-d')."', '$date_resigned')";
    $result = $atecCoop->query($sql);
    $insert = $atecCoop->insert_id;

    $sql2 = "SELECT
                p.fpayID, m.cooploanID, YEAR(p.date_resigned) as date_resigned
            FROM
                tb_cooploan_master as m
            INNER JOIN
                tb_finalpay as p
            ON
                m.coopmemID = p.coopmemID
            WHERE
                clmstID!='NULL' AND p.coopmemID='$coopmemID'";
    $result = $atecCoop->query($sql2);
    while ($row = $result->fetch_object()){
        $cooploanID = $row->cooploanID;
        $fpayID = $row->fpayID;
        $date_resigned = $row->date_resigned;
        $sql3 = "INSERT INTO tb_finalpay_detail (fpayID, cooploanID, syear, is_add) VALUES ($fpayID, $cooploanID, $date_resigned, $is_add)";
        $atecCoop->query($sql3);
    }
break;

1 个答案:

答案 0 :(得分:1)

您正在使用string concatenation operator。 使用点运算符连接一些变量后,$is_add将是一个字符串。请看这个例子:

$a = 0;
$b = 1;
$c = 1;
$d = 0;

$e = $a.$b.$c.$d;

var_dump($e);

打印出string(4) "0110"。所以你的$is_add很可能不是0或1.在插入之前尝试var_dumping $is_add并检查它的值。

如果$is_add需要为0或1,则需要使用布尔运算符。你可以尝试这样的事情:

$is_add = $tot_shrs_amt || $bnfts || $dvdnd || $loan || $grcery || $life_insrnce || $funeral_pln || $flu_vccne || $eye_glss;

如果你的其他变量之一评估为1,$is_add将为1。否则它将为0.