如何显示复选框,具体取决于在Codeigniter中选择的数字

时间:2018-08-05 08:09:43

标签: php codeigniter

如何根据下拉列表中选择的项目显示一组复选框?

我得到了一个包含“座位数”的下拉列表。我需要查看与所选席位数量相对应的席位复选框列表。

我在数据库中有一个席位列表,但是当用户在所选选项中选择一个号码时,我需要显示这些席位

现在,当我加载页面时,出现一个错误,提示未定义“ noSeat”变量

我的控制器

class Timetable extends CI_Controller {

    public function index()
    {
        $this->load->model('Queries');
        $seats = $this->Queries->getSeats($noSeats);
        $template['page'] = "InsertMultipleRecords/insertMultipleRecords";
        $template['page_title'] = "BUS SCHEDULE";
        //$this->load->view('template', $template);

        $this->load->view('InsertMultipleRecords/insertMultipleRecords', ['seats'=>$seats]);
    }

我的模特

public function getSeats(){
{
    $query = $this->db->from('seat')->where('noSeats', $noSeats)->get();
    if($query->num_rows() > 0){
        return $query->result();
    }  
}
} 

我的观点

<body>
<div style="margin-bottom:2% !important;"> 
<?php echo form_open('Timetable/message'); ?>
<fieldset >     
     <h1>JOURNEY SCHEDULE</h1>     
     <br/>
     <div>
     <div>

<div >
<select  name="noSeats" class="form-control" placeholder="Seats">
                    <option value="">Seats</option>
                    <option value="45">45</option>
                    <option value="49">49</option>
                    <option value="51">51</option>
                    <option value="53">53</option>
                    <option value="56">56</option>
                    <option value="57">57</option>
                    <option value="61">61</option>
                  </select>
                </div>


                  <div >
                   <br/>
                   <input id="from-datepicker" class="form-control" type="text" name="bookingDate" placeholder="Date of Journey"></>
                </div>
                <div >

              </div>
                  <br/>
               <div>                   
                   <input id="mytextbox" class="form-control" type="text" name="busNumber" placeholder="T 618 CCG"></>
                </div>

                <br/>

                <br/>
                </div>
                <div>
                <?php echo form_error('busNumber', '<div class="text-danger">', '</div>'); ?>
                <?php echo form_error('bookingDate', '<div class="text-danger">', '</div>'); ?>
                </div>

                </div>
                <div>
                    <?php echo form_error('seatId', '<div class="text-danger">', '</div>'); ?>
                 <table cellspacing="50"  align="center">
                    <thead>
                       <tr>
                       <th> <input type="button" id="toggle" value="All" onClick="do_this()"/></th>
                       <th>Seat</th>
                       </tr>
                    </thead>

                    <tbody>
                    <?php if(count ($seats)):?>
                    <?php foreach ($seats as $seat):?>
                    <tr>
                        <td><input type="checkbox" name="seat_id[]" value=<?php echo $seat->seatNumber;?>></td>
                        <td><?php echo $seat->seatLabel;?></td>
                    </tr>
                    <?php endforeach;?>

                    <?php else:?>
                    <td>No Records Founds!</td>
                    <?php endif;?>

                    </tbody>
                    </table>
                    </div>
                    <br/>

                  <br/>

                     <div>
                <?php echo form_submit(['name'=>'submit', 'value'=>'Set Schedule', 'class'=>'btn btn-info pull-center']); ?>
                </div>
                  </fieldset>

              <?php echo form_close(); ?>
              </div>    
              </body>

我的HTML页面

enter image description here

但是在该表的顶部,存在以下错误

 A PHP Error was encountered
Severity: Notice

Message: Undefined variable: noSeats

Filename: controllers/Timetable.php

Line Number: 10

Backtrace:

File: /home/n17ljw1lcuti/public_html/ticketing/core/admin/application/controllers/Timetable.php
Line: 10
Function: _error_handler

File: /home/n17ljw1lcuti/public_html/ticketing/core/admin/index.php
Line: 315
Function: require_once

  A PHP Error was encountered
Severity: Notice

Message: Undefined variable: noSeats

Filename: controllers/Timetable.php

Line Number: 10

Backtrace:

File: /home/n17ljw1lcuti/public_html/ticketing/core/admin/application/controllers/Timetable.php
Line: 10
Function: _error_handler

File: /home/n17ljw1lcuti/public_html/ticketing/core/admin/index.php
Line: 315
Function: require_once

一张表格,该表格根据所选座位显示座位复选框

enter image description here

1 个答案:

答案 0 :(得分:0)

问题是您尝试使用名为$noSeats的变量,而不对其进行初始化。您需要对其进行初始化才能使用它。例如:

$noSeats = 45;
$seats = $this->Queries->getSeats($noSeats);

$noSeats = 45;
$query = $this->db->from('seat')->where('noSeats', $noSeats)->get();