第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用codeigniter更新表中的確切行

如何使用codeigniter更新表中的確切行

PHP
元芳怎么了 2021-10-08 10:05:30
我的查看頁(yè)面:在這張圖片中,我正在獲取類似loan no, 的數(shù)據(jù)partyname,coll.amt使用date(即它顯示了我給出時(shí)那個(gè)特定日期的數(shù)據(jù),來(lái)自“集合”表)如果我輸入了loan no2的代表 amt,但我沒(méi)有給loan no1、3。當(dāng)我按下ok button代表 amt 時(shí),應(yīng)該在該“集合”表中更新確切的貸款編號(hào)和日期。我的型號(hào)代碼:public function batchinsert($data){    $session_data = $this->session->userdata('logged_in');    $data['username'] = $session_data['repname'];    $LDate = $this->input->post('CDate');    $date = str_replace('/', '-', $LDate);    $newDate = date("Y-m-d", strtotime($date));    $lno = $this->input->post("Sno");    $count = count($data['Sno']);    for($i = 0; $i<$count; $i++){         $entries2[] = array(                           'receive_amt'=>$data['ramt'][$i],            );     }    $this->db->where('loanno',$lno);    $this->db->where('collection_date',$newDate);    $this->db->update_batch('collection',$entries2);    //        $this->db->insert_batch('test', $entries2);    redirect('Collection_Entry','refresh');}我的控制器代碼:public function Collection_Insert(){    $this->load->model('User_model');    $result = $this->User_model->batchinsert($_POST);}我的查看頁(yè)面代碼:<table class="table table-bordered table-striped table-xxs" id="tb3">    <thead>        <tr>            <th>Loan No</th>            <th>Party Name</th>            <th>Coll.Amt</th>            <th>Rep Amt</th>        </tr>    </thead>    <tbody>    <?php    //echo '<pre>';print_r($result2);exit();    if(!empty($query)){        foreach($query as $row){    ?>        <tr >        <td ><input style="width:50px" type="text" class="form-control input-xs" name="Sno[]" id="Sno" value="<?=$row['loanno'];?>"></td>        <td> <input style="width:180px" type="text" class="form-control input-xs" name="name[]" id="Amount" value="<?=$row['pname'];?>"></td>        <td ><input style="width:80px" type="text" class="form-control input-xs amt" name="Amount[]" id="Bankname" value="<?=$row['collection_amt'];?>"></td>請(qǐng)解決這個(gè)問(wèn)題。
查看完整描述

1 回答

?
HUX布斯

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊

如果您只想對(duì)ramt[]具有非空值的輸入進(jìn)行更新,您可以為每個(gè)輸入文本名稱分配一個(gè)鍵,以便稍后識(shí)別它:


<table class="table table-bordered table-striped table-xxs" id="tb3">

    <thead>

            <tr>

    <th>Loan No</th>

    <th>Party Name</th>

    <th>Coll.Amt</th>

    <th>Rep Amt</th>

    </tr>

    </thead>

    <tbody>

        <?php

        //echo '<pre>';print_r($result2);exit();

        if(!empty($query)){

            foreach($query as $key => $row){ // added $key as index

            ?>

                <tr >

                    <td ><input style="width:50px" type="text" class="form-control input-xs" name="Sno[<?php echo $key ?>]" id="Sno" value="<?=$row['loanno'];?>"></td>


                    <td> <input style="width:180px" type="text" class="form-control input-xs" name="name[<?php echo $key ?>]" id="Amount" value="<?=$row['pname'];?>"></td>


                    <td ><input style="width:80px" type="text" class="form-control input-xs amt" name="Amount[<?php echo $key ?>]" id="Bankname" value="<?=$row['collection_amt'];?>"></td>


                    <td ><input style="width:80px" type="text" class="form-control input-xs ramt" name="ramt[<?php echo $key ?>]" id="Chqamt" value="<?=$row['receive_amt'];?>" autofocus></td>

                </tr>


            <?php

            }

        }?> 

    </tbody>

</table>

并過(guò)濾您的batchinsert()函數(shù)的輸入數(shù)據(jù):


public function batchinsert($data){

    $session_data = $this->session->userdata('logged_in');

    $data['username'] = $session_data['repname'];

    $LDate = $this->input->post('CDate');

    $date = str_replace('/', '-', $LDate);

    $newDate = date("Y-m-d", strtotime($date));

    $lno = $this->input->post("Sno");

    $ramt = $this->input->post("ramt"); // added ramt input variable

    $count = count($data['Sno']);

    $updateArray = array();

    for($x = 0; $x < sizeof($lno); $x++){


        if (!empty($ramt[$x])) { // this will only insert data on loanno which have non-empty ramt values

            $updateArray[] = array(

                'loanno' => $lno[$x],

                'receive_amt'=> $ramt[$x]

            );

        }

    }

    $this->db->where('collection_date',$newDate);

    $this->db->update_batch('collection',$updateArray,'loanno');

    //        $this->db->insert_batch('test', $entries2);

    redirect('Collection_Entry','refresh');

}

這只會(huì)遍歷非空ramt[]輸入,然后只更新動(dòng)態(tài)loanno值和靜態(tài)collection_date值。


// Example query output : 

// UPDATE `collection`

// SET

// `receive_amt` = 

// CASE 

//     WHEN `loanno` = '1' THEN 1 

//     WHEN `loanno` = '3' THEN 2 

//     WHEN `loanno` = '6' THEN 3 

//     WHEN `loanno` = '17' THEN 4 

//     ELSE `receive_amt`

// END 

// WHERE `collection_date` = '2019/01/09' AND `loanno` IN ('1','3','6','17')


查看完整回答
反對(duì) 回復(fù) 2021-10-08
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)