duancan1900 2015-10-30 12:02
浏览 115

标题中的CodeIgniter搜索框

My search box is included in the header. I want so that when I type any word for a search it grabs results from my database and goes to the search view page with results. My header is also included on different controllers.

here is my controller

public function index()
{ 
    if($this->input->post('submit')) 
    {
        if($this->input->post('search') == '')
        {
            redirect('search');
        }
        $keyword        =   $this->input->post('search');
        $data['rows']   =   $this->search_model->search($keyword);
    }
    $this->load->view('header');
    $this->load->view('search',$data);
    $this->load->view('footer');
}

here is my model

function search($keyword)
{
    $this->db->like('title', $keyword);
    $this->db->or_like('type', $keyword);
    $query  =   $this->db->get('mytable');
    return $query->result();
}

here is my view

<form class="navbar-form" role="search" action="<?php echo base_url();?>search" method="post">
      <div class="input-group cust-input">
        <input type="text" class="form-control" placeholder="Search" name="search">
        <div class="input-group-btn ">
       <button class="btn btn-default cust-searchbtn" type="submit" name="submit"><i class="glyphicon glyphicon-search"></i></button>

        </div>
      </div>
    </form>

But when I search for something it redirects to my search page with empty results. I want to do search in the header and send results to my search page where I show the results on that page.

  • 写回答

2条回答 默认 最新

  • drgc9632 2015-10-30 12:24
    关注
    public function index()
    { 
      if(isset($this->input->post('submit'))) 
      {   
        $keyword        =   $this->input->post('search');
        $this->load->model('model_name');
        $data['rows']   =   $this->search_model->search($keyword);
        print_r($data['rows']); //print and check the results are fetching or not---then load it to view.
        $this->load->view('header');
        $this->load->view('search',$data);
        $this->load->view('footer');
      }
      else
      {
         redirect('search');
      }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图