Jump to content

[SOLVED] adding username to image


runnerjp

Recommended Posts

  • Replies 128
  • Created
  • Last Reply

Top Posters In This Topic

ok can any 1 help me with this lil bit

 

$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`= $pID' ;
$q = mysql_query($sql);
if($q){
  $row = mysql_fetch_array($q);
  if(!empty($row)){
    echo '<img src="http://www.runningprofiles.com/members/images/'
         $pID. $row['ext']. '" />';
  }
}else{
  echo 'Error: Image not found.';
}

 

how can i right this properly  $pID. $row['ext']. '" />';

Link to comment
Share on other sites

Once again, why are you querying the database for the extension? There are only a limited number of possible extensions and really, there  is no need wasting resources querying for it.

 

As for how to write your line properly....

 

echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. $row['ext'] . '" />';

Link to comment
Share on other sites

ok

$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`='$pid;
$q = mysql_query($sql);
if($q){
  $row = mysql_fetch_array($q);
  if(!empty($row)){
    echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />';
  }
}else{
  echo 'Error: Image not found.';
}*/

should do it  if 2 things

 

1.`user_id`='$pid; how would i display this correctly?

 

2. echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />';  is this correct way of showin  id.ext?? or 1.jpg

Link to comment
Share on other sites

ok

$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`='$pid;
$q = mysql_query($sql);
if($q){
  $row = mysql_fetch_array($q);
  if(!empty($row)){
    echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />';
  }
}else{
  echo 'Error: Image not found.';
}*/

should do it  if 2 things

 

1.`user_id`='$pid; how would i display this correctly?

 

2. echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. "." $row['ext'] . '" />';  is this correct way of showin  id.ext?? or 1.jpg

 

If I am correct in thinking, the URL you should use single quotes for the "." as '.' because at the moment you've broken the URL up.

echo '<img src="http://www.runningprofiles.com/members/images/' . $pID . '.' .$row['ext'] . '" />'

 

Sam

Link to comment
Share on other sites

What i would of done is if the picture is always in the same place on the screen.... just echo the username ontop of the image using absolute position in div tags... so it looks like its part of the picture when infact its actually "above the image"

 

Plus if its using a $Username.. when ever the name is changd it will change according.. how ever this won't work if the picture is not always in the same place.

Link to comment
Share on other sites

is this correct way of showin  id.ext?? or 1.jpg

 

Where in your code do you toell it to display 1.jpg if no record is found? You don't! This thread is getting out of hand. You seriously need to learn the basics and come back to this idea in a few months when you get it.

Link to comment
Share on other sites

 <?$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=$pid;
$q = mysql_query($sql);
if($q){
  $row = mysql_fetch_array($q);
  if(!empty($row)){
   echo '<img src="http://www.runningprofiles.com/members/images/' . $pID . '.' .$row['ext'] . '" />'
  }
}else{
  echo 'Error: Image not found.';
}
?> 

 

but thorpe i know how to display 1.jpg if the image insnt found i will add that later.. my point is that i cant get the users image first!! 

 

echo '<img src="http://www.runningprofiles.com/members/images/' . $pID . '.' .$row['ext'] . '" />'... has a nexpected T_STRING

Link to comment
Share on other sites

$sql = 'SELECT `ext` FROM `user_image` WHERE `user_id`=' . $_GET['id'];


$q = mysql_query($sql);
if($q){
  $row = mysql_fetch_array($q);
  
	 echo 'emma';
  if(!empty($row)){
   echo '<img src="http://www.runningprofiles.com/members/images/' . $pID. $row['ext'] . '" />';
  }
}else{
  echo 'Error: Image not found.';
}

 

fixed the error on my own lol showing i can fix some errors lol but not one not displaying the image :S

Link to comment
Share on other sites

Seriously, I think this thread has gone on long enough. If you can't fix your problems with 100+ replies to your thread, there are bigger issues.

 

Firstly, try some debugging. Where the hell does $pID come from? What does it contain (echo it to find out)? Does what it contains relate to an actual image name?

 

I'll say it again, I see no reason for you to be using a database in this situation at all. However, you seam to have completely ignored this (and I would assume alot of other) good advice.

 

Seams to me you don't have a good grasp of the basics yet. Maybe a read of the free book in my signiture could get you heading down the right path?

Link to comment
Share on other sites

im doing this with tinkering ect.. i do have a problem

 

$query = "SELECT ext FROM user_image WHERE user_id='$user_id' LIMIT 1"; 

 

it give me #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = "SELECT ext FROM user_image WHERE user_id='$user_id' LIMIT 1"' at line 1

 

 

can any 1 enlighten me on this please?

 

oh and thrope... if there are 2 images by the user in the folder e.g 1.jpg  1.gif then the script will show more then 1 ?

Link to comment
Share on other sites

i do have anouther weeee problem 

 

the code always trys to find the users id with the ext....

 

if(isset($q)){
while ($row = mysql_fetch_array($q)) {
    echo "<img src='http://www.runningprofiles.com/members/images/".
         $pid . "." . $row['ext']. "' />";
  }
}else{
  echo "<img src='http://www.runningprofiles.com/members/images/pic.jpg />";
  } 

 

 

it wont echo the pic.jpg if there are no files...how comes?

 

Link to comment
Share on other sites

like

$sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$username' LIMIT 1";

$q = mysql_query($sql) or die("Error running query:".mysql_error());

if($q){

  $row = mysql_fetch_array($q);

  if(file_exists($row))

    echo "<img src='http://www.runningprofiles.com/members/images/".

        $pid . "." . $row['ext']

        . "' />";

}{

else

  echo 'Error: Image not found.';

  } 

 

 

 

Link to comment
Share on other sites

ok this is wired  had it all working now wont display the echo or an image

 

$sql = "SELECT `ext` FROM `user_images` WHERE `user_id`='$username' LIMIT 1"; 
$q = mysql_query($sql) or die("Error running query:".mysql_error());
if($q){
  $row = mysql_fetch_array($q);
  if(!empty($row)){
    echo "<img src='http://www.runningprofiles.com/members/images/".
         $pid . "." . $row['ext']
         . "' />";
  }
}else{
  echo 'Error: Image not found.';
  }

 

 

no errors just doent display anything...a blank page yet it did afew minutes ago :S

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.