I want to build a gallery using Photoswipe.
The images are stored in the database with json encoded format:
[{"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"}]
What's happening: the images are not showing up.
The problem: the following code:
style="background-image: url('.$myImage1.');"
href="'.$myImage1.'"
src="'.$myImage1.'"
Is retrieving the following (see the code and the neon green numbers):
background-image: url();
href
src(unknown)
What's wrong here? Before, I managed to make images display, in another page, by using the following: src="'.$myImage = $myArray[0]['name'].'"
. And it worked (wasn't using Photoswipe).
For Photoswype, I'm having all the requirements mentioned here. It seems to work, the image space is created and if I click there, appears the following:
I checked also the following links:
How to use PHP inside css file [duplicate]
and tested to do the way they say: <? echo $myImage1; ?>
That didn't work.
Note: in case seeing the code in a context would help:
print_r($myArray1);
doesn't retrieve values
$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>';}
Working case:
print_r($myArray);
retrieves values
$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"/>';
My question: How do I make this work?