dstt1818 2015-11-16 12:37
浏览 7

基于codeigniter的活动记录结果内爆();

I have model that returned an object like this :

MODEL

public function getAllNama() {
    $this->db->select('nama');
    $query = $this->db->get('tbl_user');
    return $query->result();
}

Controller

$data['users'] = $this->model_user->getAllNama();
$this->load->view('it_team/view_manual_entry', $data);

In view, I have a problem to manipulate it on html. In my case, I use auto completed based jquery like this

<input id="data_user"type="text" data-provide="typeahead" data-items="4" 
    data-source='[<?=  ?>]'
    ">

Which is, in atribute data-source have a string format like this : data-source="["nama1", "nama2"]"

So, based that,

foreach(users as user){
   echo $user->nama; 
}

which is print user1user2, How can I pass this on data-source with suitable string format ?

I know implode, but i have try many ways, but still no success. Any solution it so appreciated.. Thanks

  • 写回答

2条回答 默认 最新

  • dounao1856 2015-11-16 12:46
    关注

    Try this:

     <?php
        $names = '';
        foreach($users as $user){
           $names .= '"'.$user->nama.'",'; 
        }
        $names = trim($names, ','); ?>
        <input id="data_user"type="text" data-provide="typeahead" data-items="4" 
            data-source='[<?php echo $names;?>]'>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂