This topic is locked
[SOLVED]

 Display images in a page

12/29/2016 10:44:46 AM
PHPRunner General questions
T
tiagoperes author

Good afternoon,
been creating a page where want to display images from the database in a loop dependent in one condition.
Problem: The image appears broken;
How was that done?


<img src="'.$row['Special_Image'].'" alt="" class="deal-thumb">



How is the database saving the record:



Example, [{"name":"files\/93969494_pinetki_yr4vrtsp.jpg","usrName":"93969494_pinetki.jpg","size":53204,"type":"image\/jpeg","searchStr":"93969494_pinetki.jpg,!:sStrEnd"}]
See it live
Display image from URL in db

J
jacques 12/30/2016



Good afternoon,
been creating a page where want to display images from the database in a loop dependent in one condition.
Problem: The image appears broken;
How was that done?


<img src="'.$row['Special_Image'].'" alt="" class="deal-thumb">



How is the database saving the record:



Example, [{"name":"files\/93969494_pinetki_yr4vrtsp.jpg","usrName":"93969494_pinetki.jpg","size":53204,"type":"image\/jpeg","searchStr":"93969494_pinetki.jpg,!:sStrEnd"}]
See it live
Display image from URL in db


look for my_json_decode in help

admin 12/30/2016

Check this article for inspiration:

https://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm
my_json_decode function allows you to parse JSON, extract file name and display it.

T
tiagoperes author 1/10/2017



Check this article for inspiration:

https://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm
my_json_decode function allows you to parse JSON, extract file name and display it.


Thanks for the feedback.
Got it to work in the following way:

// Make the query:

$sql = "*****";

$result = mysqli_query($conn, $sql);





if (mysqli_num_rows($result) > 0) {

// output data of each row

while ($row = mysqli_fetch_assoc($result)) {

$image = $row['Special_Image'];

$myArray = json_decode($image, true);

// Fetches the first ID



echo '<div class="deal-item col-md-12">

<div class="col-md-4">

<img src="'. $myImage = $myArray[0]['name'].'" alt="" class="deal-thumb">

<p class="expire">The deal expires '.$row['End_Date'].'</p>

</div>

(...)

</div>';

}

} else {

echo "0 results";

} // End