brokenmech Posted February 8, 2010 Share Posted February 8, 2010 $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. Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 8, 2010 Share Posted February 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/#findComment-1008977 Share on other sites More sharing options...
brokenmech Posted February 8, 2010 Author Share Posted February 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/#findComment-1008982 Share on other sites More sharing options...
brokenmech Posted February 8, 2010 Author Share Posted February 8, 2010 I added this to the top of this file, but it didn't return any errors or notices relevant to this file ini_set('display_errors',1); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/#findComment-1008988 Share on other sites More sharing options...
PFMaBiSmAd Posted February 8, 2010 Share Posted February 8, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/#findComment-1009001 Share on other sites More sharing options...
brokenmech Posted February 8, 2010 Author Share Posted February 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/#findComment-1009007 Share on other sites More sharing options...
brokenmech Posted February 8, 2010 Author Share Posted February 8, 2010 What is the proper syntax when the variable $user_id is an int? In my sql query should this be in quotes or not? Do you think this could be a factor in my problem? Quote Link to comment https://forums.phpfreaks.com/topic/191387-php-mysql-help-needed/#findComment-1009013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.