0
我有一個while
循環從SQL數據庫獲取用戶名。 謝謝hpyerlink的用戶名
我有一個while
循環從SQL數據庫獲取用戶名。 謝謝hpyerlink的用戶名
你這樣做是錯的。
此處的會話沒有用處。
只有你留意到的只是一個普通的超鏈接,它會將用戶ID轉到下一頁。有想法嗎?
echo "<tr></td><a href='viewallforms.php?id=$user_id'>$name</a></td></tr>';
,然後你將在viewallforms.php的用戶ID從$_GET['id']
可變
您可以使用參數使用view.php?名稱=值傳遞給其他頁。 你想要一個解決方案在你的way.check它。
<?php
if ($result)
{
echo "<table border=\"1\" align=\"center\">";
echo "<th><center>User ID</center></th>";
echo "<th><center>Name</center></th>";
while ($row = mysql_fetch_array($result))
{
$name = $row['first_name'] . ' ' . $row['last_name'];
$user_id = $row['user_id'];
echo "<tr><td>";
echo $user_id
echo "</td><td>";
echo '<form method="post" action="viewallforms.php">
<input type="submit" value="' . $name . '"/>
<input type="hidden" name="sumbit" value="true"/>
<input type="hidden" name="userid" value="$user_id"/></form>';
echo "</td></tr>";
}
}
echo "</table>";
if (isset($_POST['submit'])) {
}
else {
$_SESSION['user'] = $_POST['userid'];
echo $user_id;
}
?>
becaue你有$ user_id = $ row ['user_id'];在循環內部,所以每次$ user_id都會改變。它在循環結束時停止改變。因此,在var中你總是會獲取最後一個用戶名。 –