簡體   English   中英

如果帳單號不在數據庫中,如何警告消息

[英]how to alert the message if the bill no is not in a database

如果帳單號不在數據庫中,如何提醒消息

<form action="<?=site_url('TipUp_Loan/Bill_Delete')?>" class="form-inline" method="POST">
    <div class="modal-body">
        <div class="form-group">
            <label>Bill No: </label>
            <input type="text"  id="bill" class="form-control" name="Search1" autofocus>
        </div>

    </div>
    <div class="modal-footer text-center">
        <button type="submit" id="Delete" onclick="return confirm('Are You sure want to Delete')" class="btn btn-primary" >Delete<i class="icon-bin position-left"></i></button>
    </div>
</form>

這是查看代碼。

public function Bill_Delete(){
    $session_data = $this->session->userdata('logged_in');
    $data['username'] = $session_data['username'];
    $Search = $this->input->post('Search1');
    $this->User_model->Bill_Delete($Search);


}

這是一個控制代碼...

public function Bill_Delete($Search)
{

  $this->db->where('billno', $Search);
  $this->db->delete('salesitem');
  $this->db->where('no', $Search);
  $this->db->delete('salesbill');
  //echo "Successfully delted";
  $this->session->set_flashdata('Add', 'You Deleted The Bill No Successfully');

redirect("Inventory/Bill_Entry","refresh");

}

這是模型代碼...

我的問題是如何查找數據庫中是否存在帳單號,如果不在數據庫中,它將提示消息...

您需要使用$this->db->affected_rows(); 賬單上返回true的函數將被刪除,否則返回false。

希望這會有所幫助。

        //In controller function
        public function Bill_Delete(){
         $this->form_validation->set_rules('billno','billno','exist[salesitem.billno]');
            if ($this->form_validation->run() == FALSE) 
            {
                    return $this->set_response( array(), validation_errors(),  'Bill No not exits' );
            }
            else
            {
                $session_data = $this->session->userdata('logged_in');
                $data['username'] = $session_data['username'];
                $Search = $this->input->post('Search1');
                $this->User_model->Bill_Delete($Search);
            }
        // In MY_Form_validation library
        function exist($str, $value){       

              list($table, $column) = explode('.', $value, 2);    
              $query = $this->CI->db->query("SELECT COUNT(*) AS count FROM $table WHERE $column = $str'");
              $row = $query->row();

              return ($row->count > 0) ? FALSE : TRUE;

            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM