I am selecting data from my db and store them in a list in bahn.php. Then I echo the values of the objects to display them in index.php.
Now, I want to update the status of the displayed object by clicking on the “accept”-button. This is working so far, but I have to reload the page manually to get a new created list without the updated object. What do I need to do to just click on accept and the list gets refreshed by itself?
I tried to reload location, header location etc. after my submit, but then the update did not work.
bahn.php
<?php
require_once("config.php");
require("bahn.php");
function get_bahn() {
$bahn_list = array();
$db = db_connection();
$statement = $db->prepare(
"SELECT bahn.bahnid ... FROM bahn WHERE bahn.status = 0");
$statement->execute();
while($row = $statement->fetch()) {
$new_bahn = new bahn(...);
array_push($bahn_list, $new_bahn);
}
return $bahn_list;
}
function create_bahn_list($bahn_list) {
if (empty($bahn_list)) {
echo '<div class="alert alert-danger fade show">
...
</div>';
} else {
foreach($bahn_list as $key => $val) {
$statusid = $val->get_bahnid();
echo '...
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#info'.$val->get_bahnid().'"> More info</button>
<div class="modal fade" id="info'.$val->get_bahnid().'" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">
<div class="modal-content">
...
<div class="modal-footer">
<form method="POST">
<button type="submit" name="accept" class="btn btn-success btn-sm">Accept</button>
</form>
</div>
...';
}
}
if(isset($_POST['accept'])) {
$db = db_connection();
$statement = $db->prepare(
"UPDATE bahn
SET status = 1
WHERE bahn.bahnid = $statusid");
$statement->execute();
}
}
?>
index.php
<div class="row" data-masonry='{"percentPosition": true }'>
<?php
$bahn_list = get_bahn();
create_bahn_list($bahn_list);
?>
</div>