Dony Aditya
Dony Aditya

Reputation: 43

Call image in database using php

I want to ask.

I have table :

1. No = 01 
2. ID = 001
3. Password = 001
4. IMAGE = 001

I save my images in folder Images.

If I have 100 record how i call image at database?? but I wont change my table at database

I can call my image when I change my data in table

1. No = 01 
2. ID = 001
3. Password = 001
4. IMAGE = Images/001.jpg

Sample SCRIPT:

   $user =$_SESSION['username'];
   $data=mysql_query("select * from user WHERE ID=$user ");
   while($baris=mysql_fetch_array($data))
   {
      echo "<img src=\"$baris[IMAGE]\"> ";
   }

Upvotes: 0

Views: 3205

Answers (3)

GautamD31
GautamD31

Reputation: 28763

Try like

echo "<img src='Images/".$baris['IMAGE'].".jpg'> ";

And if you have saved the folder name,then use

echo "<img src='".$baris['IMAGE'].".jpg'> ";

I did'nt understand why you are storing image name without extension

Upvotes: 1

Sonu Sindhu
Sonu Sindhu

Reputation: 1792

Try this

$user =$_SESSION['username'];
$data=mysql_query("select * from user WHERE ID=$user ");
while($baris=mysql_fetch_array($data))
{
  echo "<img src='Images/".$baris[IMAGE].".jpg'> ";

}

Hope it will help

Upvotes: 0

Mark
Mark

Reputation: 8431

try to include in your path Images folder and include the file extension '.jpg' like:

$user =$_SESSION['username'];
$data=mysql_query("select * from user WHERE ID=$user ");
while($baris=mysql_fetch_array($data))
{
echo "<img src=\"Images/".$baris['IMAGE']."\">";

}

I strongly suggest that you also store the file extension (to handle .png,.gif and .jpeg) and don't use mysql_* instead use mysqli_* or PDO.

Upvotes: 4

Related Questions