如何显示票据,我想从预订页面在codeigniter的数据

问题描述 投票:0回答:1

在前一页,我填写了付款细节和submited,它显示火车预订和我想打印票,但IM没有得到目前预订的数据.我试图获得与booking_id的数据,但它没有检索数据.我可以得到检索数据与乘客_id,但它不是唯一的cz一个用户可以预订多列火车,所以它显示在数据库中的第一个条目,如果有一个乘客的多个条目.但IM不被获得数据与booking_id.帮助我!!!!

 model
       public function viewtrain($booking_id=null)
      {
        if($booking_id)
        { 
        $this->db->select('*');
        $this->db->from('booked');
        $this->db->where('booking_id=?');
        $alltrains=$this->db->get();
        return $alltrains->result();
       }
       }
view
  

  <table class="table table-type  " style="text-align:center">
  <thead>
    <tr>
      <th scope="col">Train ID</th>
      <th scope="col">Origin</th>
      <th scope="col">Destination</th>
      <th scope="col">Date</th>
      <th scope="col">Arrival Time</th>
      <th scope="col">Departure Time</th>
      <th scope="col">Class</th>
      <th scope="col">Price</th>
      <th scope="col">Action</th>
    </tr>
  </thead>
  <tbody>
  <?php if(count($alltrains)):?>
    <?php foreach($alltrains as $alltrain): ?>
    <tr class="table-type">
      <td><?php echo $alltrain->booking_id; ?></td>
      <td><?php echo $alltrain->origin; ?></td>
      <td><?php echo $alltrain->destination; ?></td>
      <td><?php echo $alltrain->date; ?></td>
      <td><?php echo $alltrain->arrivaltime; ?></td>
      <td><?php echo $alltrain->departuretime; ?></td>
      <td><?php echo $alltrain->class; ?></td>
      <td><?php echo $alltrain->price; ?></td>
      <td>
          <?php echo anchor("admin/edittrain/{$alltrain->train_id}",'Edit',['class'=>'btn btn-outline-primary','style'=>'font-size:15px;height:20px;width:40%;padding-top :0px;']); ?>
          <?php echo anchor("admin/deletetrain/{$alltrain->train_id}",'Delete',['class'=>'btn btn-outline-danger','style'=>'font-size:15px;height:20px;width:50%;padding-top :0px;']); ?>
      </td>

    </tr>
    <?php endforeach;?>
  <?php else:?>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td><h4>NO Trains Available!!</h4></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  <?php endif;?>
  </tbody>
</table>
Controller

        public function ticket($booking_id=null)
        {
        $this->load->model('user_model');
        $alltrains=$this->user_model->viewtrain($booking_id);
        $this->load->view('ticket',['alltrains'=>$alltrains]);
        }
        
mysql codeigniter codeigniter-3
1个回答
1
投票

数据没有被检索是因为你的模型中的格式不对,我把正确的格式写在下面,看看对你有没有帮助。 模型

 if($booking_id)
 { 
     $this->db->select('*');
     $this->db->from('booked');
     $this->db->where('booking_id', $booking_id);
     $alltrains=$this->db->get();

     return $alltrains->result();
 }
© www.soinside.com 2019 - 2024. All rights reserved.