1 | initial version |
There are several ways to pass a PHP variable from a while loop to the following page:
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
echo "<a href='next_page.php?id=$id'>$name</a>";
}
In the above code, the ID value is appended to the URL, which can be accessed on the next page using the $_GET superglobal.
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$_SESSION['id'] = $id;
$_SESSION['name'] = $name;
echo "<a href='next_page.php'>$name</a>";
}
In this code, we have stored the ID and name values in session variables, which can be retrieved on the next page using the $_SESSION superglobal.
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
setcookie('id', $id, time()+3600);
setcookie('name', $name, time()+3600);
echo "<a href='next_page.php'>$name</a>";
}
In this code, we have set a cookie with the ID and name values, which can be accessed on the next page using the $_COOKIE superglobal.