非法的字符串偏移(代码点火器3)



Hi一直试图从我的数据库中检索记录,但我一直收到这个错误"严重性:警告消息:非法的字符串偏移量";在几个领域。

控制器

public function get_discount(){
if($this->session->has_userdata('logged_in')){ 
// redirect(base_url());
}
else{
$output = array();
$output['error']="failed";
$coupon_code=$this->input->post('coupon_code');
$product_price=$this->input->post('product_price');

$condition=array('coupon_code'=>$coupon_code,
'product_price'=>$product_price
);
$count['discount']= $this->Form_model->get_discount('coupon',$condition);
foreach($count['discount'] as $row)
{
echo json_encode($count['discount']);

if($count > 0){
$discount = $row['discount'] / 100;
$total = $discount * $product_price;
$array['discount'] = $row['discount'];
$array['product_price'] = $product_price - $total;

$output['success']="success";
echo json_encode($output);
}
}
}
}

这是我的型号

public function get_discount($data){
$sql = "SELECT * FROM coupon WHERE (coupon_code = ? ) AND  status= 'valid' ";
$query = $this->db->query($sql, array($data['coupon_code']));
$result = $query->row() ; 
if($query->num_rows()==1){
return $result;
}
}

这是我的观点

<form action="/get_discount" method="post">
<div class="form-group">
<h4 class="text-warning">*Optional</h4>
<label>Coupon Code</label>
<input class="form-control" name="coupon_code" type="text" id="coupon_code" />
<input type="hidden" value="<?php echo $product->product_price?>" id="price" />
<div id="result"></div>
<br style="clear:both;" />
<button class="btn btn-primary" id="activate">Activate Code</button>
</div>
</form>
<div class="form-group">
<label>Total Price</label>
<input class="form-control" type="number" value="<?php echo $product->product_price?>" id="total" readonly="readonly" lang="en-150" />
</div>
</div>
</div>

调用get_data()时参数太多。它只有$condition应该是唯一的参数。

$count['discount']= $this->Form_model->get_discount($condition);

错误是因为$data是第一个参数,您在调用中将字符串'coupon'传递给它。

最新更新