Saturday, June 2, 2012

View Images In Mysql Table

View Images In Mysql  Table

This post I have not really stored images inside the mysql table,But included path of the image to the folder where images have been stored.
Previous post you have created table called "biodata"  in the table add another column called images.


The completed table look tike bellow

Person Id:-1
First Name:-Scarlett
Last Name:-Johansson
Age:---
Image:-
Person Id:-2
First Name:-Clooney
Last Name:-Anderson
Age:---
Image:-
Person Id:-3
First Name:-Kate
Last Name:-Hudson
Age:---
Image:-

Ages displaying is disabled due to real world Examples First you have to create folder named "images in your web root.Name the images as above mysql table images column.Then create following PHP file and run.
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_database", $con);


$result = mysql_query("select * from biodata");

while($row = mysql_fetch_array($result))
  {
echo "<table bgcolor=#dda767>";
echo "<tr bgcolor=#ffffff><td><font size='5'>". "Person Id:-"."</font></td>";
echo "<td><font color='blue' size='5'>".$row['id']."</font></td></tr>";

  echo "<tr bgcolor=#ffffff><td><font size='5'>". "First Name:-"."</font></td>";
echo "<td><font color='blue' size='5'>". $row['FirstName'] . "</font></td></tr>";

echo "<tr bgcolor=#ffffff><td><font size='5'>". "Last Name:-"."</font></td>";
echo "<td><font color='blue' size='5'>". $row['LastName']."</font></td></tr>";

echo "<tr bgcolor=#ffffff><td><font size='5'>". "Age:-"."</font></td>";
echo "<td><font color='blue' size='5'>". $row['Age']."</font></td></tr>";

echo "<tr bgcolor=#ffffff><td><font size='5'>". "Image:-"."</font></td>";
 $valimage= $row['image'];
              
               echo "<td><img src = '$valimage'></td></tr></table> ";
 }mysql_close($con);
?>

No comments:

Post a Comment