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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan