如果帐单号不在数据库中,如何警告消息

时间:2018-11-01 10:14:33

标签: php codeigniter

如果帐单号不在数据库中,如何提醒消息

<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");

}

这是模型代码...

我的问题是如何找到数据库中没有帐单,如果不在数据库中,它将提示消息...

2 个答案:

答案 0 :(得分:1)

您需要使用$this->db->affected_rows();函数,该函数会删除在帐单上返回true的结果,否则返回false。

希望这会有所帮助。

答案 1 :(得分:0)

        //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;

            }