0

i needed to fetch some names and image of vegetable from my database and since saving image from mysql table and then retrieving it on web page is a bad idea, i have the images saved in the images/vegetable folder within the workspace. i am working on cloud9 and using the following code snippet:

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

            echo "<tr>";
            echo "<td>" . $row['name'] . "</td>";
            echo "<td>" . $row['price'] . "</td>";



            $images_src="/images/vegetable/".$row['name'].".jpg";
           //  echo "<td>" .$images_src ."</td>"; //this displays the image src correctly

           echo "<td> <img src=$images_src ></img> </td>";
            echo "</tr>";
        }

        echo "</table>";

however after execution it displays the broken image icon. where am i going wrong? is achieving image source this way illegal?

ritika
  • 61
  • 1
  • 10
  • i have tried using '' and "" for images_src in echo " "; but it doesnt help – ritika Sep 24 '14 at 06:17
  • You need to provide the full path to the image. For example: http://yoursiteurl.com/images/vegetables/. Check the page source and click on the image link to see if the images are loading or not. – radiopassive Sep 24 '14 at 06:21
  • its still showing broken image, saving the broken image shows No File and while i am trying to copy the url and pasting in another tab of browser it says 'Cannot GET /bhaskey/eshopper/images/vegetable/potato.jpg' which the complete image url – ritika Sep 24 '14 at 06:30
  • ps, when i am trying out with random google image, it is working fine but not with my images saved in the workspace – ritika Sep 24 '14 at 06:45

1 Answers1

0

First of all the img tag is a singleton tag. You need not add a closing img tag for it.

Another one is you need to give the full url to the image resources like this:

echo " http://localhost/yourwebsite/$images_src> "; (if in local server )

or echo " http://www.yourwebsite.com/$images_src> "; (if in live server )

Try it and let me know if you are still having an issue

radiopassive
  • 556
  • 1
  • 5
  • 15
  • i am using this code now : "$images_src= "https://".$IP."/eshopper/images/vegetable/".$row['name'].".jpg";" its still not working. i have also removed the closing tag for img – ritika Sep 24 '14 at 07:39
  • $row['name'] is fetched from mysql table and are name of vegetables like potato or tomato. Images are saved in the "image/vegetable" folder with the same name. – ritika Sep 24 '14 at 08:50
  • then your url shall be https://sitename.com/images/vegetables/tomato(suppose).jpg right? So do you have an image called (suppose) tomato.jpg ? I just ran the above code with a dummy image and the image worked fine. I am pretty sure the problem is in the image url – radiopassive Sep 24 '14 at 08:53
  • i am workin on cloud9, and my trial project is say market. inside market is the images/vegetable folder having all the images. and i am trying to create the image url by concatenatimng the fixed part of it that is /market/images/vegetable/ and then i am trying to concatenate the variable part by $row['name'] . and this long time of unsuccessful trial is just encouraging me that it is an illegal way to attempt – ritika Sep 24 '14 at 09:21
  • however http://stackoverflow.com/questions/17340959/php-concatenating-of-image-link-in-echo is suggesting otherwise, i am failing to achieve what i want – ritika Sep 24 '14 at 09:30