Jump to content

Recommended Posts

$user_id          = $result['by_id'];
	var_dump ($user_id);

 

at this point var_dump() returns string(2) "10" , which is correct

 

but

 

get_profile_image($user_id);

 

 $icon_link =  get_profile_image($user_id);
function get_profile_image($user_id)
	{

	$sql ="SELECT user_name FROM member_profile WHERE user_id = $user_id";
      $query        = @mysql_query($sql);
      $result 		= @mysql_fetch_array($query);
	  
      $profile_name     = $result['user_name']; 

	$sql ="SELECT file_name FROM pictures WHERE user_id = '$user_id'";  
	  $query        = @mysql_query($sql);
      $result 		= @mysql_fetch_array($query);
	  
	      $user_icon        = $result['file_name'];

	     if ($user_icon  =="")
	            $user_icon = "placeholder.jpg" ;

	  $icon_link             = "<a href='http://www.vloggerville.com/members/".$profile_name."'target='_parent'>"."<img src='/pictures/".$user_icon."'align='left' width='60' height='60' border='0'/></a>";

	  //echo $icon_link;
	return   $icon_link;
    }

 

This will give me the correct avatar and profile link 90% of the time, but gives me the wrong Avatar and profile link unpredictably. I can't figure out what I'm doing wrong. I am very new to this and am trying to learn from what I can find on these forums. Can someone tell me what I am doing wrong here?

 

So the user id going into the function in this case is 10, but the user id/avatar and profile link being returned is 1.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/
Share on other sites

gives me the wrong Avatar and profile link unpredictably

What exactly is wrong about them? Values for someone else? The placeholder.jpg for when the query does not return anything?

 

And please remove the @ from in front of the mysql_ function calls as they would hide php errors that would help determine why your code is not working. The fact that you have @'s in your code suggests you are getting errors with the queries or with fetching data from the result set.

Yes sometimes I get a seemingly unpredictable result as in an avatar that is correctly linked to it's own profile page, but has nothing to do with the user _id I am trying to get the data for.

 

I will do as you suggest. Thanks I didn't even know that is what the @ was for.

You are going to need to investigate what is happening with your data and your code on your system.

 

Where is $result['by_id'] coming from?

 

What is the code in between where $user_id is set and where you call the get_profile_image() function?

 

Is this repeatable? When the same person navigates to the same point, is the result the same?

 

Is your data in the database correct? Do you have unique data or are the results you are getting because the data is actually wrong or are there multiple values (right or wrong) for any specific id? Is the example of a id of '10' resulting in data for the id of '1' an actual case and if so, have you looked at the data for an id of 10 and an id of 1 to see if there is anything about them that would explain the results? Is the wrong value always for the same id?

 

That just the problem. The error is erratic.

 

90% of the time the function returns the correct avatar and link, and when it doesn't the results are not repeatable. I have spent ages trying to figure this out.

 

 

I noticed also that using var_dump() as I did in the example above causes other parts of the code to fail. ???? Is this normal? I thought var_dump() would not effect the rest of the code?

 

 

Anyway thanks for looking at my problem. I'm keep investigating and trying things.

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.