【问题标题】:Pick from a list and save it to database从列表中选择并将其保存到数据库
【发布时间】:2016-05-20 21:39:44
【问题描述】:

我正在为客户创建一个具有 Codeigniter 3 HMVC 风格的网站,他希望在此页面上有一个功能,登录的用户可以选择自己的新闻。例如,如果用户选择尤文图斯,那么他将收到添加的所有尤文图斯名称的新闻。基本上就像添加到购物车或购物车一样,我从来没有做过这样的事情,所以这是我创建的:

控制器

    class Usernews extends MY_Controller{

    function __construct() {

    parent::__construct();

    $this->load->model('model_usernews');
    $this->load->module('template');

}

function search(){
      $data['pageTitle'] = "User news";
    $search_name = $this->input->post('band');
    $data['bands'] = $this->model_usernews->get_clubs($search_name);
     $data['module'] = "usernews";
    $data['view_file'] = "usernews";
    $this->template->user_news($data);
}

}

型号

   class Model_usernews extends CI_Model {

    function get_table(){
    $table = "bands";
    return $table;
    }

    function get_clubs($keyword) {
    $table = $this->get_table();
    $this->db->like('band_name', $keyword, 'both');
    $this->db->order_by('band_name');
    $query=$this->db->get($table);
    return $query;
    }

和部分视图

        <div class="row">
        <div class="col-lg-8 ">
        <!-- USER BAND LIST -->
        <!-- LIST OF ARTICLES -->
        </div>
        <div class="col-lg-4">
     <div class="row">
     <?php $attributes = array('id' => 'list_of_bands');
          echo form_open('usernews/search',$attributes); ?>
      <input type="text" class="form-control" name="band"
       placeholder="Search">
       <button type="submit" class="btn btn-default btn-lg" >OK</button>
        <?php echo form_close(); ?>
       <?php  $num_rows = $listing->num_rows();
        if($num_rows > 0){ ?>
        <ul id="the_bands" class="list-unstyled">
        <li> <?php foreach ($listing->result() as $row){?>
            <li><?php echo $row->band_name; ?>" ><button id="add_band"  
            class="btn btn-default btn-sm" >Add to list</button></li>
          <?php } 
           } else{
            echo "<p>No bands with that name</p>"; 
             } ?>
            </div> 
            </div>

我可以在数据库中搜索乐队,但现在我一无所知。

【问题讨论】:

    标签: php jquery ajax codeigniter


    【解决方案1】:

    您认为使用$bands 而不是$listing

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 2020-09-15
      相关资源
      最近更新 更多