根据eventID获取数据

Fetching data based on eventID

这里是新手。我的目标是显示基于 eventID 的数据。例如我在 eventID="1" 中注册了一个数据。当我单击我的视图按钮时,模式将显示我在 eventID="1" 下注册的所有条目,依此类推。我进行了查询,但出现错误。我怎样才能使这项工作?我提供了目标的代码和屏幕截图。提前谢谢你,祝你有美好的一天。

查看:

 <div class="modal fade" id="viewModal">
        <div class="modal-dialog modal-xl">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title"></h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <table id="entryTable" class="table table-bordered table-hover" cellspacing="0">
                
        
                 <thead>         
                      <tr>
                        <th>Entry ID</th>
                        <th>Entry Name</th>  
                        <th>Owner</th>
                        <th># Of Fights</th>
                    </tr>
                </thead>
            
            <tbody>
            
            </tbody>
 
            
             </table>
            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

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

Ajax:

function view_person(eventID)
   {
   

   
   
   
    $('.form-group').removeClass('has-error'); // clear error class
    $('.help-block').empty(); // clear error string
    $('#viewModal').modal('show'); // show bootstrap modal
    $('.modal-title').text('View Entries for this Event'); // Set Title to Bootstrap modal title
    
    
      table = $('#entryTable').DataTable({ 
            dom: 'lBfrtip',
            buttons: [
               'print', 'csv', 'copy', 'excel', 'pdf'
           ],
           "processing": true, //Feature control the processing indicator.
           "serverSide": true, //Feature control DataTables' server-side processing mode.
           "order": [], //Initial no order.
           
    
           // Load data for the table's content from an Ajax source
           "ajax": {
             url : "<?php echo site_url('transaction/entryFetch')?>/" + eventID,
               "type": "POST"
           },
    
           //Set column definition initialisation properties.
           "columnDefs": [
               { 
                   "targets": [ 0 ], //first column
                   "orderable": false, //set not orderable
               },
               { 
                   "targets": [ -1 ], //last column
                   "orderable": false, //set not orderable
               },
    
           ],
    
       });
       
    
    
       
        }

控制器:

//this is my fetching inside of viewModal
    function entryFetch()
        {
            
            $list = $this->entryy->get_datatables();
            
            $data = array();
            $no = $_POST['start'];
            foreach ($list as $person) {
                $no++;
                $row = array();
                $row[] = $person->entryID;
                $row[] = $person->entryName;
                $row[] = $person->owner;
                $row[] = $person->noOfFight;
               
    
                
                
                $data[] = $row; 
            }
                
                $output = array(
                    "draw" => $_POST['draw'],
                    "recordsTotal" => $this->entryy->count_all(),
                    "recordsFiltered" => $this->entryy->count_filtered(),
                    "data" => $data,
                );
                //output to json format
                echo json_encode($output);
        }



 //this is where I specifies my button's value eventID.
    
        
      function ajax_list()
    {
        
        
        $list = $this->transactions->get_datatables();
        $data = array();
        $no = $_POST['start'];
        foreach ($list as $person) {
            $no++;
            $row = array();
            $row[] = $person->eventID;
            $row[] = $person->description;
            $row[] = $person->derbyDate;
            $row[] = $person->fightType;
            $row[] = $person->host;
            $row[] = $person->venue;            
            $row[] = $person->createdBy;
            $row[] = $person->dateCreated;
            $row[] = $person->updatedBy;
            $row[] = $person->dateUpdated;
            
     
            
           
            $row[] = '
                  <a class="btn btn-sm btn-success" href="javascript:void(0)" title="View" onclick="view_person('."'".$person->eventID."'".')"><i class="glyphicon glyphicon-pencil"></i> View';
            
            $data[] = $row;
        }
        
        $output = array(
            "draw" => $_POST['draw'],
            "recordsTotal" => $this->transactions->count_all(),
            "recordsFiltered" => $this->transactions->count_filtered(),
            "data" => $data,
        );
        //output to json format
        echo json_encode($output);
    }

型号:

    var $table = 'entries';
    var $column_order = array(null,'id','entryName','owner','noOfFights');
    var $order = array('id' => 'asc');
    var $column_search = array('id','entryName','owner','noOfFights');
 
    
    private function _get_datatables_query()
    {
        
        $this->db->from($this->table);
      
        $this->db->where('eventID',$_POST['eventid']);
     
        
        $i = 0;
        
        foreach ($this->column_search as $item) // loop column
        {
            if($_POST['search']['value']) // if datatable send POST for search
            {
                
                if($i===0) // first loop
                {
                    $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
                    $this->db->like($item, $_POST['search']['value']);
                }
                else
                {
                    $this->db->or_like($item, $_POST['search']['value']);
                }
                
                if(count($this->column_search) - 1 == $i) //last loop
                    $this->db->group_end(); //close bracket
            }
            $i++;
        }
        
        if(isset($_POST['order'])) // here order processing
        {
            $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
        }
        else if(isset($this->order))
        {
            $order = $this->order;
            $this->db->order_by(key($order), $order[key($order)]);
        }
    }
    
    
    //fetch view
    function get_datatables()
    {
        $this->_get_datatables_query();
        
        if($_POST['length'] != -1)
            $this->db->limit($_POST['length'], $_POST['start']);
            $query = $this->db->get();
            return $query->row();
            
            
           
    }
    
    function count_filtered()
    {
        $this->_get_datatables_query();
        $query = $this->db->get();
        return $query->num_rows();
    }
    
    public function count_all()
    {
        $this->db->from($this->table);
        return $this->db->count_all_results();
    }
    

您使用什么排序来显示 table?

例如,如果您按查询顺序按 Id 和 Desc 顺序在 table 中显示结果,您应该 foreach 结果并在按钮上显示 table 使用 href 将触发模态并使用 table.

中的 ID 对模态 ID 进行编号

在页面末尾,像查询table一样调用一个查询,在模态之前打开一个foreach函数,并用数据库中的id命名模态(你命名的方式然后在按钮的 href 中)。

这样你就应该得到你想要的了。

如果你还有什么不明白的,欢迎评论。