在Database中搜索值,并使用Codeigniter获取此行中的所有值 [英] Search a values in Database and get all values in this single row using Codeigniter

查看:88
本文介绍了在Database中搜索值,并使用Codeigniter获取此行中的所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果优惠券号码是由用户提供的匹配,我想要连续搜索优惠券号码,请使用Codeigniter获取此行中的所有值。

 






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();
}

控制器

  public function ven_coupon()
{
$ this-> load-> model('front');
if($ _POST){
$ number = $ _POST ['coupon'];
if(!$ this-> front-> ven_coupon($ number)){
echoNot Valid;
}
$ payment = $ this-> cart-> total();
$ discount ['discount'] =($ payment * 10)/ 100;
$ this-> load-> view('checkout',$ discount);
}
}

查看 >

 < form action =<?= base_url();?> home / ven_couponmethod =post> 
优惠券号码:< input type =textname =coupon>
< input type =submitname =submitvalue =Apply coupon>
< / form>


解决方案

你的问题不清楚。但是如果你想要数据库中的所有值,你需要修改你的控制器为:

  $ data = $ this-> front - > ven_coupon($ number); 
if(count($ data)< = 0){
echonot valid; // print error
}
else {
print_r($ data); //打印所有数据
}

这是一个基本的例子,传入加载视图。


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.

这篇关于在Database中搜索值,并使用Codeigniter获取此行中的所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆