我正在尝试创建一个用户配置文件页面。用户基于搜索选择他想要查看的用户简档。通过点击“查看个人资料”按钮,该页面应该转到profile.php,并显示用户的个人资料。php循环值 - mysql查找
现在,我只是想测试它,只显示用户的名字。这是我的代码。
我的问题是,我不知道如何将“$ userID”传递给profile.php,然后它将用于查找该用户的信息。由于该值处于while循环中,因此我不确定如何选择此循环的一次实例。
function findUsers($friend){
$search = mysql_query("Select * from users where username='$friend'");
$userLocation = mysql_query("select * from userinfo where username='$friend'");
$locationResult = mysql_fetch_array($userLocation);
$locationResultArray = $locationResult['userlocation'];
$locationExplode = explode("~","$locationResultArray");
//table column names
echo "<table>";
echo "<tr><td>";
echo "Username";
echo "</td><td>";
echo "Location";
echo "</td></td><tr><td>";
while($result = mysql_fetch_array($search)) //loop to display search
{
$userID = $result['userid']; //can I pass this value to the function since it's possible that there is more than 1 userID from the while loop?
echo $result['username'];
echo "</td><td>";
echo $locationExplode['0'];
echo ", ";
echo $locationExplode['1'];
echo "</td><td>";
?>
<form method="post" action="profile.php">
<?
echo "<input type='submit' name='profile' value='View User's Info'";
echo "</td><td>";
?>
</form>
<form method="post" action="profile.php">
<?
echo "<input type='submit' name='addfriend' value='Add Friend' />"; //code still needs to be written for this input.
echo "</td></tr>";
}
echo "</table>";
if(isset($_POST['profile'])){
$viewProfile->displayProfile($userID); //This is where I'm not sure if it's taking the correct userID.
}
}
}
?>
...和页面来显示轮廓
<?
include_once 'infoprocesses.php';
$user = new dbProcessing();
Class viewProfile{
function displayProfile($username){ //display profile pulls the user's name from the databse
echo $username; //used to test if value is being sent...nothing is being displayed
?>
<h2><?php $user->username($username);?>'s Information</h2>
<?
}
}
?>
谢谢,非常完美。我花了一点时间才弄明白,因为我没有意识到$ _GET ...必须在传递给它的页面上使用。 – user1104854 2012-01-18 00:55:26