duanlei20082008 2015-10-25 18:52
浏览 37
已采纳

从数据库php codeigniter加载图像

Im trying to load images from the database, i can get the full string and no display on the image and when i use the full array I get a array message.

here is the model :

public function get_webstore($webstore_id = '') {
        /* get video */
        if (empty($webstore_id)) {
            $webstores = $this->get('webstore');
        } else {
            $webstores = $this->get('webstore', $webstore_id);
        }

        $webstore_array = array();
        foreach ($webstores as $webstore) {


            $singleWebstorePair = array();
            if (!empty($webstore['images'])) {
                $allWebstores = unserialize($webstore['images']);
                foreach ($allWebstores as $allWestores) {
                    $singleWebstorePair[] = str_replace("./", "", base_url($allWebstores));
                }
            }
            $webstore_array[] = array(
                'id' => $webstore['id'],
                'title' => $webstore['title'],
                'content' => $webstore['content'],
                'images' => $singleWebstorePair,
                'created' => $webstore['created']
            );
        }
        return $webstore_array;
    }

and here is the front end code

<div class="col-md-12" style="height: 225px;">
                <div class="col-md-4 text-center thumbnail123">
                    <img class="thumbnail" width="225px" src="<?php echo $webstore['images']?>.jpg"/>
                    <h3><?php echo $webstore['title']; ?></h3> 
                    <p>Date Added: <?php echo date('d-m-y', strtotime($webstore['created'])) ?></p>
                     <hr>

                    <hr>
                </div>

here is the controller if needed:

   public function __construct() {
        parent::__construct();
        $this->load->model("post");
        $this->load->database();
        $this->load->helper("url");


    }
    public function index() {

    $this->data['posts'] = $this->post->get_webstore($limit=null, $offset=null); // calling Post model method getPosts()
    $this->data['page_title'] = 'Store';
    $this->layout("pages/webstore", $this->data);

and the error:

Severity: Notice

Message: Array to string conversion

Filename: pages/webstore.php

Line Number: 45

thanks guys

  • 写回答

1条回答 默认 最新

  • dsbfbz75185 2015-10-25 19:52
    关注

    When you populate your array, you set 'images' => $singleWebstorePair,˙ which is an array.

    In your template, your are echoing this:

    <img class="thumbnail" width="225px" src="<?php echo $webstore['images']?>.jpg"/>

    But here $webstore['images'] is an array. So if $webstore['images'] holds multiple image source, then loop through it:

    <?php foreach($webstore['images'] as $image) : ?>
       <img class="thumbnail" width="225px" src="<?php echo $image ?>.jpg"/>
    <?php endforeach; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)