我正在嘗試創建一個用戶配置文件頁面。用戶基於搜索選擇他想要查看的用戶簡檔。通過點擊「查看個人資料」按鈕,該頁面應該轉到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