try to add session_start()
to the beginning of volgende.php
Changing query variable, then executing it again
-
11-06-2023 - |
Pergunta
I am working on a PHP page that shows a table with query results. I want 2 buttons, with 'next' and 'previous', which change a variable used in this query:
SELECT les.lesuur, les.clustercode, les.lokaal, les.leraar, les.status
FROM les, zitin
WHERE zitin.leerlingnummer='$dimGebruiker'
AND zitin.clustercode=les.clustercode
AND les.dag='$huidigedag'
ORDER BY les.lesuur
$huidigedag is the one that should be changed. This is what I have in the beginning of the PHP code:
session_start();
if (!isset($_SESSION["huidigedag"])){
$_SESSION["huidigedag"] = 1;
}
$huidigedag = $_SESSION["huidigedag"];
Then, I added a link to the two buttons (arrow images):
<a href="volgende.php">
(volgende means next)
This is volgende.php:
<?php
$_SESSION["huidigedag"] = $_SESSION["huidigedag"] + 1;
header("location:leerlingrooster.php");
?>
However, when I click the button, nothing happens. I echo'd $huidigedag, and noticed it stayed on 1, without changing.
Solução
Outras dicas
I would change volgende.php to:
<?php
session_start();
$_SESSION["huidigedag"] = (!isset($_SESSION["huidigedag"])) ? 1 : ($_SESSION["huidigedag"] + 1);
header("location:leerlingrooster.php");
exit;
?>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow