i want to search coupon number in a row if coupon number is match given by user get all values in this single row using Codeigniter. Here is My Code.
Model
public function ven_coupon($coupon)
{
$where = array(
'number' => $coupon,
);
$this->db->select()
->from('vendor_coupons')
->where($where);
$data = $this->db->get();
return $data->result_array();
}
Controller
public function ven_coupon()
{
$this->load->model('front');
if ($_POST) {
$number = $_POST['coupon'];
if (!$this->front->ven_coupon($number)) {
echo "Not Valid";
}
$payment = $this->cart->total();
$discount['discount'] = ($payment*10)/100;
$this->load->view('checkout',$discount);
}
}
View
<form action="<?=base_url();?>home/ven_coupon" method="post">
Coupon Number: <input type="text" name="coupon">
<input type="submit" name="submit" value="Apply Coupon">
</form>
You question is not clear what actually you need. But if you want all values from database than you need to modify your controller as:
$data = $this->front->ven_coupon($number);
if(count($data) <= 0){
echo "not valid"; // print error
}
else{
print_r($data); // print all data
}
This is basic example you can store them into variable and pass into load view.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.