使用Photoswipe显示DB编码的图像

时间:2017-03-14 09:29:55

标签: javascript php html css json

我想使用Photoswipe构建图库。

图像以json编码格式存储在数据库中:

[{"name":"files/130813-263472-LA-Dive-Bar-HMS-Bounty-Bar_e12bad6z.jpg","usrName":"130813-263472-LA-Dive-Bar-HMS-Bounty-Bar.jpg","size":62595,"type":"image/jpeg","searchStr":"130813-263472-LA-Dive-Bar-HMS-Bounty-Bar.jpg,!20100826_marias_560x372.jpg,!125255351_5169310e93.jpg,!:sStrEnd"},{"name":"files/20100826_marias_560x372_nbajgoth.jpg","usrName":"20100826_marias_560x372.jpg","size":44958,"type":"image/jpeg"},{"name":"files/125255351_5169310e93_f0udoyh3.jpg","usrName":"125255351_5169310e93.jpg","size":131453,"type":"image/jpeg"}][{"name":"files/130813-263472-LA-Dive-Bar-HMS-Bounty-Bar_e12bad6z.jpg","usrName":"130813-263472-LA-Dive-Bar-HMS-Bounty-Bar.jpg","size":62595,"type":"image/jpeg","searchStr":"130813-263472-LA-Dive-Bar-HMS-Bounty-Bar.jpg,!20100826_marias_560x372.jpg,!125255351_5169310e93.jpg,!:sStrEnd"},{"name":"files/20100826_marias_560x372_nbajgoth.jpg","usrName":"20100826_marias_560x372.jpg","size":44958,"type":"image/jpeg"},{"name":"files/125255351_5169310e93_f0udoyh3.jpg","usrName":"125255351_5169310e93.jpg","size":131453,"type":"image/jpeg"}]

发生了什么:图片没有显示。

问题:以下代码:

  1. style="background-image: url('.$myImage1.');"
  2. href="'.$myImage1.'"
  3. src="'.$myImage1.'"
  4. 正在检索以下内容(请参阅代码和霓虹绿色数字):

    ![enter image description here

      

    background-image:url();

         

    HREF

         

    SRC(未知)

    这里有什么问题?之前,我设法通过使用以下内容在另一页中显示图片:src="'.$myImage = $myArray[0]['name'].'"。它工作(没有使用Photoswipe)。

    对于Photoswype,我提到了here提到的所有要求。 它似乎工作,图像空间被创建,如果我点击那里,出现如下:

    enter image description here

    我还检查了以下链接:

    How do i run PHP inside CSS

    How to use PHP inside css file [duplicate]

    并按照他们说的方式进行测试:<? echo $myImage1; ?>

    那不起作用。

    注意:以防在上下文中查看代码会有所帮助:

    print_r($myArray1);无法检索值

    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        while ($row = mysqli_fetch_assoc($result)) {
            $category=$row['Company_Category'];
            $name=$row['Company_Name'];
            $subcategory=$row['Company_Subcategory'];
            $image1 = $row['Image'];
            $myArray1 = json_decode($image1, true);
            print_r($myArray1);
            $myImage1 =$myArray1[0]['name'];
        echo '<figure class="gallery-image-item" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" style="background-image: url('.$myImage1.')">
                  <a href="'.$myImage1.'" itemprop="contentUrl" data-size="960x640">
                     <img class="gallery-thumb" src="'.$myImage1.'" itemprop="thumbnail" alt="Image description" />
                   </a>
                   <figcaption class="hidden caption" itemprop="caption description">'.$row['Description'].'</figcaption>
                </figure>';}
    

    工作案例:

    print_r($myArray);检索值

    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        // output data of each row
           $row = mysqli_fetch_assoc($result);
            $image = $row['Company_Logo'];
            $myArray = json_decode($image, true);
            echo '<img src="'.$myImage = $myArray[0]['name'].'" alt="" class="img-responsive"/>';
    

    我的问题:我该如何使用?

0 个答案:

没有答案