【问题标题】:How to fetch table data when select value from select box using codeigniter使用codeigniter从选择框中选择值时如何获取表数据
【发布时间】:2016-06-07 03:50:35
【问题描述】:

View.php

这是codeigniter中的视图文件。

<div class="table-responsive">
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th>#</th>
                <th>Year Range</th>
                         <select>
                         <?php foreach ($result as $value): ?>
                          <td></td>
                <option><?php echo $value['year_key'] ?></option>
              </select>

                <th>Species</th>
                <th>Data</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
        </thead>
        <tbody>

            <?php foreach ($result as $value): ?>
                <tr>
                    <td></td>
                    <?php foreach ($value['speces_key'] as $key => $value2): ?>

                        <td><?php echo $key; ?></td>
                        <td><?php echo $value2['data'] ?></td>

                    <?php endforeach; ?>
                </tr>

            <?php endforeach; ?>
        </tbody>
    </table>
</div>

我的问题:我单击年份范围选择框并从选择框中选择值并使用 codeigniter 根据选择值获取表数据

【问题讨论】:

    标签: php jquery mysql codeigniter


    【解决方案1】:

    请使用 ajax 调用更改年份范围,例如,

    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>Year Range</th>
                             <select id="year">
                             <?php foreach ($result as $value): ?>
                              <td></td>
                    <option><?php echo $value['year_key'] ?></option>
                  </select>
    
                    <th>Species</th>
                    <th>Data</th>
                    <th>Edit</th>
                    <th>Delete</th>
                </tr>
            </thead>
            <tbody>
    
                <?php foreach ($result as $value): ?>
                    <tr>
                        <td></td>
                        <?php foreach ($value['speces_key'] as $key => $value2): ?>
    
                            <td><?php echo $key; ?></td>
                            <td><?php echo $value2['data'] ?></td>
    
                        <?php endforeach; ?>
                    </tr>
    
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <script>
    $('#year').on('change',function () {
            var year = $('#year').val();
            $.ajax({
                url: 'url for get data',
                type: 'POST',
                data: {year: year},
                success: function (a) {
                    data = JSON.parse(a);
                    #get data and print data with each loop
                }
            });
        });
    </script>
    

    【讨论】:

      猜你喜欢
      • 2018-09-19
      • 2014-09-27
      • 2019-03-23
      • 2013-06-03
      • 2021-03-25
      • 2017-06-03
      • 1970-01-01
      • 2012-10-13
      相关资源
      最近更新 更多