Jump to content

Recommended Posts

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

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

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

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.