私はユーザープロファイルページを作成しようとしています。ユーザは、検索に基づいて閲覧したいプロフィールを選択する。 「プロファイルの表示」ボタンをクリックすると、ページは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