我有一个要插入的表,我想在每个表中插入两次。但在我的代码中,将插入唯一的第一笔金额。你能不能给我一些建议,因为我在CI方面做得不好。
这是我的控制器
function addloads(){
$data = array(
'member' => $this->input->post('member'),
'cell_number' => $this->input->post('cell_number'),
'amount' => $this->parseAmount($this->input->post('amount')),
'total' => $this->parseAmount($this->input->post('total')),
'status' => $this->input->post('status'),
'added_by' => $this->session->userdata('admin_id'),
'date' => date('Y-m-d',strtotime($this->input->post('date'))),
'after_rebate' => $this->input->post('rebate'),
);
$this->db->where('mem_id',$this->input->post('member'));
$this->db->insert('loading_service',$data);
$status = $this->input->post('status');
if($status == 'paid'){
$data2 = array(
'incomefrom_id' => $this->input->post('member'),
'income_name' => 'Load',
'date_created' => date('Y-m-d',strtotime($this->input->post('date'))),
);
$this->db->set('time_created', 'NOW()', FALSE);
$this->db->insert('incomefrom',$data2);
$amount = $this->parseAmount($this->input->post('amount'));
$total = $this->parseAmount($this->input->post('total'));
$all = $total - $amount;
$data3 = array(
'amount' => $all,
'incomefrom' => $this->input->post('member'),
'trans_date' => date('Y-m-d',strtotime($this->input->post('date'))),
);
$this->db->set('trans_time', 'NOW()', FALSE);
$this->db->insert('income',$data3);
$amount = $this->parseAmount($this->input->post('amount'));
$after = $this->parseAmount($this->input->post('rebate'));
$income = $amount - $after;
$data9 = array(
'amount' => $income,
'incomefrom' => $this->input->post('member'),
'trans_date' => date('Y-m-d',strtotime($this->input->post('date'))),
);
$this->db->set('trans_time', 'NOW()', FALSE);
$this->db->insert('income',$data9);
$data10 = array(
'incomefrom_id' => $this->input->post('member'),
'income_name' => 'Rebate',
'date_created' => date('Y-m-d',strtotime($this->input->post('date'))),
);
$this->db->set('time_created', 'NOW()', FALSE);
$this->db->insert('incomefrom',$data10);
}
//$this->load->view('loadingservice',$data);
//redirect(base_url('loadscontroller/loadingserviceview'));
}
这是我的视图
<form action="<?php echo base_url('loadscontroller/addloads') ?>" method="post">
<div class="row">
<div class="col-xs-6">
<div class="form-group" id="member_form">
<label for="member">Member</label>
<?php
$sql=mysql_query("SELECT * FROM member WHERE mem_is_deleted='0' ORDER BY mem_fname ASC ");
if(mysql_num_rows($sql)){
$select= '<select class="form-control" id="member" name="member" required >';
while($rs=mysql_fetch_array($sql)){
$select.='<option value="'.$rs['mem_id'].'">'.$rs['mem_fname'].' ' .$rs['mem_lname'].'</option>';
}
}
$select.='</select>';
echo $select;
?>
<p class="help-block text-danger" id="member_err"></p>
</div>
<div class="form-group" id="cell_number">
<label for="cell_number">Cellphone Number</label>
<input type="text" class="form-control" id="cell_number" name="cell_number" placeholder="" required>
<!-- <p class="help-block text-danger" id="grossamount_err"></p> -->
</div>
<div class="form-group">
<label for="amount">Amount</label>
<input type="text" id="txt1" onkeyup="sum();" value="5" hidden>
<input type="text" class="form-control " id="amount" name="amount" placeholder="00" required onkeyup="sum();">
</div>
</div>
</div>
<!-- <div class="row" id="willsend" style="display:none">
<div class="col-xs-6">
<div class="form-group">
<p>Will send <span id="lblnet"></span> to <span id="lblbaccountname"></span> <span id="lblbaccount"></span></p>
</div>
</div>
</div> -->
<div class="row">
<div class="col-xs-3">
<div class="form-group">
<label for="total">Total</label>
<input type="text" class="form-control" id="total" name="total" placeholder="00" required >
</div>
</div>
</div>
<div class="row">
<div class="col-xs-3">
<div class="form-group">
<!-- <label for="total">With Rebate</label> -->
<input type="text" id="rebate" name="rebate" >
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="form-group" style="width: 200px;">
<label for="date">Date</label>
<input type="text" class="form-control readonly datepicker" id="date" name="date" value="<?php echo date('F d, Y') ?>" required readonly>
</div>
</div>
</div>
<div class="form-group" id="status">
<label for="status">Status</label>
<select class="form-control" id="status" name="status" required style="width: 150px;">
<option selected="" value="">--select--</option>
<option value="paid">PAID</option>
<option value="unpaid">UNPAID</option>
</select>
</div>
<button type="submit" class="btn btn-default">Submit</button>
<!-- /.row -->
</form>