Home how to display uploaded picture . php ,mysql
Reply: 1

how to display uploaded picture . php ,mysql

Zuber Khan
1#
Zuber Khan Published in 2017-12-07 18:43:27Z

hey guys i am stuck at very end point of my code , my aim was to Store image path to database and store the image to a directory. and than i want to show those images. i am successfully done uploading part but now i am stuck how can i show those images on my webpage, here is my code

<?php 
  $sql    = "SELECT * FROM pictures";
  $result = mysqli_query($conn, $sql);
  $data   = mysqli_fetch_array($result,MYSQLI_ASSOC);

  while($row = mysqli_fetch_array($result))
  {
   $image_path=$row["folder_name"];
   $image_name=$row["picture_name"];

   echo "img src=".$image_path."/".$image_name." width=100 height=100";
  }
?> 
Michael T
2#
Michael T Reply to 2017-12-07 18:58:57Z

If you want to fetch associative arrays, use fetch_assoc instead, your $data is not needed here, it's simpler at the end. Also, only select the fields you need in your query. To fix your problem, You are simply missing the HTML , try this:

<?php 
  $sql    = "SELECT folder_name, picture_name FROM pictures";
  $result = mysqli_query($conn, $sql);
  if(!$result) {
      die("Error with your Query: " . mysqli_error($conn));
  }
  while($row = mysqli_fetch_assoc($result)) {
      $image_path = $row["folder_name"];
      $image_name = $row["picture_name"];
      echo "<img src=\"" . $image_path . "/" . $image_name . "\" width=\"100\" height=\"100\"></img>\n";
  }
?>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308837 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO