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

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)