Solved

image display php

Posted on 2016-07-16
9
52 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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
 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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