ユーザーがチームを作成したり、登録されている他のユーザーに契約を送信したりできるようにするスクリプトを作成しています。ログインしたユーザーがチームから脱退できるようにしたいと思います。htmlテーブルは、phpを使用してmysqlから動的に入力されます。ログインしているユーザーだけでなく、内のすべてのユーザーに削除オプションを適用するように設定できます<td></td>
。これが私が望むのに役立つコードスニペットです。基本的に、ログインしているユーザーだけに削除オプションを設定したいと思います。
Id Player
1 User 1 - No Delete Option
2 User 2 - Delete Option (Is the logged in user)
3 User 3 - No Delete Option
session_start();
$get_users_name = $_SESSION['username_u'];
$sql = ("SELECT id, username FROM user WHERE username='$get_users_name'");
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$grab_id = $row['id'];
$grab_user = $row['username'];
//the rest of the table generation done here such as <tr> etc
echo "<td>";
if ($grab_user == $get_users_name) {
echo '<a href="user_delete.php?id='.$grab_id.'" onClick="return confirm(\'Are you sure you want to withdrawl from the team?\')">'.$grab_user.'</a>';
}
else
{
echo $grab_user;
}
echo "</td>";
//the rest of the table generation done here such as </tr> etc
}
**@eastereggによってキャッチされたエコーの問題を修正するために編集