doujiufutaog59220 2017-06-19 07:31
浏览 47

循环遍历表以显示register_id =的所有图像? 在codeigniter

i've been working on a project for a while now using CodeIgniter. I want to display all images of same $register_id from the database with a foreach loop on the view.php.

Controller:

public function view($register_id = NULL){

    $data['image'] = $this->image_model->get_all_images($register_id);

    if(empty($data['image'])){
        show_404();
    }

    $data['title'] = $data['image']['register_id'];

    $this->load->view('templates/header');
    $this->load->view('portfolios/view', $data);
    $this->load->view('templates/footer');
}

Model

public function get_all_images($register_id = FALSE){
        $query = $this->db->get_where('images', array('register_id' => $register_id));
            return $query->row_array();
    }

view.php

<?php foreach ($image as $img) : ?>
<div class="col-md-3">
    <h3><?php echo $image['title']; ?></h3>
    <div class="img-box">
        <img class="post-thumb" src="<?php echo site_url(); ?>assets/images/portfolios/<?php echo $image['register_id'];?>/<?php echo $image['url']; ?>">
    </a></div>

Shows same image 14 times..

query works perfectly on phpmyadmin & shows diff. images..

  • 写回答

1条回答 默认 最新

  • douzhaiya3968 2017-06-19 10:19
    关注

    change your forloop variable. and its value variable too. may be solve.

     <?php foreach ($image as $value){?>
     <div class="col-md-3">
        <h3><?php echo $value['title']; ?></h3>
        <div class="img-box">
            <img class="post-thumb" src="<?php echo site_url(); ?>assets/images/portfolios/<?php echo $value['register_id'];?>/<?php echo $value['url']; ?>">
        </a>
      </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度