Jump to content

DIsplaying Image From Sql For Each User


mssakib

Recommended Posts

Hi

 

I want to display image for my each user.

 

This is my database

 

239806.jpg

 

 

The uname contains the username of my user and $uname = $_SESSION['user_name'] is my username variable.

 

So i want that when a user named sakib goes to the page it will show only his images. I tried but failed .. need some help. regards

 

SAKIB

Link to comment
https://forums.phpfreaks.com/topic/245618-displaying-image-from-sql-for-each-user/
Share on other sites

Here is what i tried

 

 

<?php


$con = mysql_connect("localhost","root","rdbhaxor");  // EdIT ThIs - 
mysql_select_db("reg", $con);

$sql = "SELECT link FROM myimg WHERE uname='www.gogole.com'";
  $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());

    

$img = mysql_result($result,1);	
echo $img;


?>

<html>
<img src=<?php  echo $img; ?> width="104" height="142" />
</html>

 

 

 

But it only gives 1 image according to the image ID

 

<?php
$user_id = (int)$_SESSION['user_id'];
$sql = mysql_query("select * from myimg where loginid = $user_id");
while($row = mysql_fetch_assoc($sql)){
$image = $row['link'];
echo "<img src='$image' />";
}
?>

 

Why are you storing the entire url of a local file? What will you do if the domain name changes, or the image path? You will now have to do some fancy regex to fix it.

 

I feel you should just store the file name.

 

What I usually do is store the file name in one column and the extension in a second column. But I don't recommend storing the whole file path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.