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
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

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.