2015-11-04 176 views
0

我的代碼有什麼問題?由於$is_add,行不會顯示。但是,當我將其更改爲$tot_shrs_amt行顯示和is_add的值爲1字段is_add(tinyint(1)),行不會顯示

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; 

我覺得這裏的問題。

$is_add = $tot_shrs_amt.$bnfts.$dvdnd.$loan.$grcery.$life_insrnce.$funeral_pln.$flu_vccne.$eye_glss; 
+2

你有元音短缺你不;) –

+0

是的。我做到了獨一無二。 aeiou :) – Micaela

+0

是'$ is_add = $ tot_shrs_amt。$ bnfts。$ dvdnd。$ loan。$ grcery。$ life_insrnce。$ funeral_pln。$ flu_vccne。$ eye_glss; '這等於1? – Saty

回答

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; 

這樣$is_add將是1,如果你的其他變量的一個計算結果爲1,否則爲0。

+0

你可以把它變成一個數組嗎?從'$ tot_shrs_amt'到'$ eye_glss'並傳遞給$ is_add?謝謝 – Micaela