无法在控制器中生成数据的html并显示在下拉列表中

时间:2015-10-02 11:03:29

标签: php jquery ajax codeigniter

我想在从下拉列表中选择区域后显示餐厅。但我的代码没有显示餐厅名称和该餐厅的菜单按钮请告诉我我错误的地方

这是我的观看代码

    <div id="restaurant">


    </div>

这是控制器代码

     public function get_rests()
    {

        $cit_id = $this->input->post('cit_id');
        $area = $this->input->post('areaID');
        $where = array('city_id'=>$cit_id,'city_area_id'=>$area);


        $html = '

        <div class="container" id="">


            <table align="centre" class="table table-condensed table-striped table-hover no-margin"style="width:70%" id="">

                <thread>

                    <tr style="width: 56%;">
                        <th>
                            No.

                        </th>
                        <th style="">
                            Restaurant Names
                        </th>
                    </tr>

                </thread>
                <tbody>

                <?php $i=1;foreach($result as $row){
                    ?>

                    <tr id="<?php echo $row->restaurant_id; ?>" class="res_id">
                        <th style="">
                            <?php echo  $i++; ?>

                        </th>
                        <th style="">
                            <?php echo $row->restaurant_name; ?>




                        </th>

                        <th style="width: 1%" >
                            <a href="<?php echo base_url();?>index.php/BulkRecipe_Controller/bulk_recipe/<?php echo $row->restaurant_id;?>"  class="btn btn-warning" <i class="glyphicon-edit"></i>See Menu</a>

                        </th>
                    </tr>
                <?php } ?>

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

        ';
        echo $html;

这是我的模型代码视图

function select_record($table, $where = NULL){

    $this->db->select();
    if($where)
        $this->db->where($where);
    $this->db->from($table);
    $query = $this->db->get();
    //  echo $this->db->last_query();
    return $query->result();
}

脚本代码

 function get_rests(){

        var city_id = $('#city_id').val();
        var area_id = $("#area_id").val();
        $.ajax({
            type: "POST",
            url: "<?=base_url();?>index.php/Bulk_Controller/get_rests",
            data: {cit_id: city_id,areaID: area_id},
            dataType: "text",
            cache:false,
            success:
                function(data){
                    // alert(data);
                    $('#restaurant').html(data);
                }
        });
    }

1 个答案:

答案 0 :(得分:0)

您没有调用模型函数来从数据库表中获取数据。

public function get_rests()
{

    $cit_id = $this->input->post('cit_id');
    $area = $this->input->post('areaID');
    $where = array('city_id'=>$cit_id,'city_area_id'=>$area);

    $result= $this->your_model->select_record('table_name',$where);
    $html = '

    <div class="container" id="">


        <table align="centre" class="table table-condensed table-striped table-hover no-margin"style="width:70%" id="">

            <thread>

                <tr style="width: 56%;">
                    <th>
                        No.

                    </th>
                    <th style="">
                        Restaurant Names
                    </th>
                </tr>

            </thread>
            <tbody>

            <?php $i=1;foreach($result as $row){
                ?>

                <tr id="<?php echo $row->restaurant_id; ?>" class="res_id">
                    <th style="">
                        <?php echo  $i++; ?>

                    </th>
                    <th style="">
                        <?php echo $row->restaurant_name; ?>




                    </th>

                    <th style="width: 1%" >
                        <a href="<?php echo base_url();?>index.php/BulkRecipe_Controller/bulk_recipe/<?php echo $row->restaurant_id;?>"  class="btn btn-warning" <i class="glyphicon-edit"></i>See Menu</a>

                    </th>
                </tr>
            <?php } ?>

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

    ';
    echo $html;