jamesjmann Posted March 27, 2011 Share Posted March 27, 2011 Here's a function I use for displaying a member's profile using $_GET <?php function view_profile ($username) { include_once "connect.php"; $query = "SELECT * FROM fans WHERE username = '$username'"; $result = mysql_query($query); $row = mysql_fetch_array($result); $count = mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $username = $row["username"]; $name = $row["name"]; $email = $row["email"]; $region = $row["region"]; $country = $row["country"]; $gender = $row["gender"]; $status = $row["status"]; $subscription = $row["subscription"]; $time_registered = $row["time_registered"]; $date_registered = $row["date_registered"]; $birthdate = $row["birthdate"]; $age = $row["age"]; $last_time = $row["last_time"]; $last_date = $row["last_date"]; $default_photo = $row["default_photo"]; $about_me = $row["about_me"]; echo $name; echo $email; echo $status; echo $username; } } ?> The only problem is, its not echoing the member's information when the function gets called. I used a variable called "$count" and echoed that to see if it was getting any results, and it is, it's just the while loop isn't working and i don't know why as I used an identical function like this for another script. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/231822-profile-problem/ Share on other sites More sharing options...
KevinM1 Posted March 27, 2011 Share Posted March 27, 2011 The mysql_fetch functions move a read-only marker through the result set. Since you only have one result, the line of $row = mysql_fetch_array($result) which is outside the while-loop is grabbing your only result. The function call within the loop conditional can't grab anything, so the loop doesn't even execute. So, in short, remove the first $row = mysql_fetch_array($result) line. Link to comment https://forums.phpfreaks.com/topic/231822-profile-problem/#findComment-1192715 Share on other sites More sharing options...
jamesjmann Posted March 27, 2011 Author Share Posted March 27, 2011 The mysql_fetch functions move a read-only marker through the result set. Since you only have one result, the line of $row = mysql_fetch_array($result) which is outside the while-loop is grabbing your only result. The function call within the loop conditional can't grab anything, so the loop doesn't even execute. So, in short, remove the first $row = mysql_fetch_array($result) line. Thank you so much! That works exactly! Link to comment https://forums.phpfreaks.com/topic/231822-profile-problem/#findComment-1192740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.