gpt4 book ai didi

php - 无法在 Controller 中制作数据的 html 并显示在下拉列表选择上

转载 作者:行者123 更新时间:2023-12-01 05:37:39 25 4
gpt4 key购买 nike

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

这是我的查看代码

    <div id="restaurant">


</div>

这是 Controller 代码

     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;

这是我的模型代码 View

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);
}
});
}

最佳答案

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

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;

关于php - 无法在 Controller 中制作数据的 html 并显示在下拉列表选择上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32905786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com