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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-04-28 21:40:50 +0000
Seen: 16 times
Last updated: Apr 28 '23
How can records be counted from a category that is retrieved through another PHP and SQL query?
What is the method for showing errors in mysqli_query?
How can Laravel establish a connection with a MySQL database located remotely?
How can a web application be developed to send distinct emails upon clicking the SUBMIT button?
How can a PHP function be used to retrieve an HTML table?
How can multiple queries be merged into a single stored procedure in MySQL?
What does "waiting for handler commit" mean in relation to the slow writes experienced in MySQL 8?