dongritan5654 2016-05-08 03:51
浏览 67
已采纳

更新codeigniter中的视图表单模型

I was wrote this function in my model :

public function get_writers()
{
    $this->db->select('writer');
    $query = $this->db->get('news');
    return $query->result_array();
}

And I want to run a foreach loop on result of this array in my view file :

<label for="writer">Writer</label>
<select name="writer" id="writer">
    <?php foreach (??? as $each): ?>
        <option value="<?php echo $each['id'] ?>"><?php echo $each['writer'] ?></option>
    <?php endforeach; ?>
</select>

But I don't know what should I write in the first parameter in foreach loop.Can anybody help me with this ? Thanks

  • 写回答

2条回答 默认 最新

  • drecy22400 2016-05-08 04:16
    关注

    You should call the function get_writers() in controller like :-

    $writers = $this->your_model->get_writers();
    

    Then you need to assign this $result variable data in view section like :-

     $this->view->load('view_page',array('writers'=>$writers));
    

    After that you can use that variable data in form in view section.

    <label for="writer">Writer</label>
    <select name="writer" id="writer">
        <?php foreach ($writers as $each): ?>
            <option value="<?php echo $each['id'] ?>"><?php echo $each['writer'] ?></option>
        <?php endforeach; ?>
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊