Solved

image display php

Posted on 2016-07-16
9
48 Views
Last Modified: 2016-07-16
<?php
$link2 = "http://localhost:888/dropzone/uploads";
$image = "/uploads";

$sql = "SELECT id, file_name FROM files";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["file_name"] . "- Image: ". <img src= "<?php echo $image.$row['file_name']; ?>"> . "<br>";

    }
} else {
    echo "0 results";
}
$conn->close();

?>

Open in new window


The above code works if I do not include this line (I get the correct list of data):
<img src= "<?php echo $image.$row['file_name']; ?>">

I need the image to be displayed
0
Comment
Question by:doctorbill
  • 6
  • 3
9 Comments
 
LVL 9

Assisted Solution

by:Moussa Mokhtari
Moussa Mokhtari earned 500 total points
ID: 41714547
@doctorbill
its just a syntax error
change you echo line to be like this
 echo "id: " . $row["id"]. " - Name: " . $row["file_name"] . "- Image: ". "<img src=".'"$image.$row['file_name']"'."><br>";

Open in new window

0
 

Author Comment

by:doctorbill
ID: 41714569
Sorry - still not working
0
 

Author Comment

by:doctorbill
ID: 41714587
<?php
$link2 = "http://localhost:888/dropzone/uploads";
$image = "uploads/";

$sql = "SELECT id, file_name FROM files";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["file_name"] . "- Image: ". "<img src=".$row["file_name"]." /> " . "<br>";

    }
} else {
    echo "0 results";
}
$conn->close();

?>

Open in new window


The above code does not give a page error but still only shows an image placeholder
This is the url from the image placeholder:
http://localhost:888/development/dev/html5/DropZone/test4.txt

I need to append the following to the image name:
uploads/
So the url will be:
http://localhost:888/development/dev/html5/DropZone/uploads/test4.txt
0
 

Author Comment

by:doctorbill
ID: 41714590
This is now working:

<?php
$link2 = "http://localhost:888/dropzone/uploads";
$image = "uploads/";

$sql = "SELECT id, file_name FROM files";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["file_name"] . "- Image: ". "<img src=".$image.$row["file_name"]." /> " . "<br>";

    }
} else {
    echo "0 results";
}
$conn->close();

?>

Open in new window

0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:doctorbill
ID: 41714599
Now this is working, how do I dictate an image width
0
 
LVL 9

Accepted Solution

by:
Moussa Mokhtari earned 500 total points
ID: 41714607
Hard code them

<?php
$link2 = "http://localhost:888/dropzone/uploads";
$image = "uploads/";

$sql = "SELECT id, file_name FROM files";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["file_name"] . "- Image: ". "<img src=".$image.$row["file_name"]." width='200px' height='200px'/> " . "<br>";

    }
} else {
    echo "0 results";
}
$conn->close();

?>

Open in new window

1
 

Author Comment

by:doctorbill
ID: 41714609
Awesome - thanks
0
 
LVL 9

Expert Comment

by:Moussa Mokhtari
ID: 41714610
You're welcome :)
0
 

Author Closing Comment

by:doctorbill
ID: 41714614
Completed
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now