im currently working on a table that shows selected values out of my database. For that I made the rows clickable to open a Popup as shown. I want to get the values out of my selected row into the popup to process them. It doesnt work for me, can someone show me for my code? Im new to coding and this is my first project so please be nice. For Example I want the ID ($row["ID"]) out of my database shown in the Popup on $row["Titel"]. At the moment its called "Abstelone" in the picture Table Popup
<?php
require 'config.php';
session_start();
$prüfer_id = $_SESSION['prüfer_id'];
if (!isset($prüfer_id)){
header('location:logout.php');
}
$select = $conn->prepare("SELECT * FROM `projektantrag` WHERE pruefer_ID =? OR pruefer2_ID = ?");
$select->execute([$prüfer_id, $prüfer_id]);
$Ausgabe = $select->fetchAll();
$select = $conn->prepare("SELECT * FROM `projektantrag` WHERE pruefer_ID =? OR pruefer2_ID = ?");
$select->execute([$prüfer_id, $prüfer_id]);
$row = $select->fetch(PDO::FETCH_ASSOC);
$OriginalBeschreibung = $row['Beschreibung'];
$FileDownload = explode('/', $OriginalBeschreibung);
$FileActualName = strtolower (end($FileDownload));
$select_profile = $conn->prepare("SELECT * FROM `user` WHERE ID = ?");
$select_profile->execute([$prüfer_id]);
$fetch_profile = $select_profile->fetch(PDO::FETCH_ASSOC);
$email = $fetch_profile['email'];
if(isset($_POST['submit'])){
$select = $conn->prepare("SELECT * FROM `projektantrag` WHERE ID = ?");
$select->execute($ID);
$Ausgabe = $select->fetchAll();
$Titel = $Ausgabe['Titel'];
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anträge anzeigen</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">
<link rel="stylesheet" href="css/style1.css">
<link rel="stylesheet" href="css/dialoge.css">
</head>
<body>
<nav>
<a href=""><img src="css/logo.png"></a>
<ul>
<li><a href="prüfer_page.php">Benutzerprofil</a></li>
<li><a class="active" href="Anträge_anzeigen.php">Anträge anzeigen</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
<?php
//Error Message
if(isset($message)){
foreach($message as $message){
echo '
<div class="message">
<span>'.$message.'</span>
<i class="fas fa-times" onclick="this.parentElement.remove();"></i>
</div>
';
}
}
?>
<table id="meineTabelle" data-role="table" class="content"
data-mode="columntoggle" data-column-btn-text="Spalten">
<thead>
<div class="tablehead">
<tr>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">1.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">2.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">3.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<th class="thblackborder" data-priority="">4.Projektant</th>
<th class="thblackborder" data-priority=""></th>
<tr>
<th class="">ID</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Vorname</th>
<th class="">Nachname</th>
<th class="">Titel</th>
<th class="">Standort</th>
<th class="">Klasse</th>
<th class="">Beginn</th>
<th class="">Abgabe</th>
<th class="">Beschreibung</th>
<th class="">Status</th>
<th class="">Erstellt</th>
</tr>
</tr>
</div>
</thead>
<tbody>
<?php
foreach ($Ausgabe as $row) {
?>
<form>
<tr onclick="dialogOeffnen('loslegen-dialog')">
<td>
<?php echo $row["ID"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname2"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname2"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname3"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname3"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Vorname4"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Nachname4"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Titel"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Standort"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Klasse"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Beginn"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Abgabe"] . "<br>"; ?>
</td>
<td>
<center><a href=<?php echo "uploads/" . $FileActualName?>">Link</a></center>
</td>
<td>
<?php echo $row["Genehmigt"] . "<br>"; ?>
</td>
<td>
<?php echo $row["Erstellt"] . "<br>"; ?>
</td>
</tr>
</form>
<?php
}
?>
</tbody>
</table>
<div id="body-overlay"></div>
<div class="dialog" id="loslegen-dialog">
<a href="#" role="button" class="dialog-schließen-button" onclick="dialogSchliessen('loslegen-dialog')">
<i class="fas fa-times"></i>
</a>
<div class="textarea">
<h1><?php echo $row["Titel"] ?></h1>
<textarea placeholder="Platz für Bemerkungen" name="Bemerkungen" id="" cols="30" rows="10"></textarea>
</div>
<form classaction="">
<div class="txt_field">
<input type="text" name="email" value="<?= $fetch_profile['email'];?>" required>
<span></span>
<label>E-Mail</label>
</div>
<div class="txt_field">
<input type="text" name="password" required>
<span></span>
<label>Passwort</label>
</div>
<input type="submit" value="Bestätigen" name="submit">
<div class="signup_link"></div>
</form>
</div>
<script src="dialoge.js"></script>
</body>
</html>
</body>
This reason that this hasn't been answered is because you're actually asking for quite a lot of work to be done to make this happen.
In essence, you're looking to pass data from your table
into a modal dialog <div class="dialog" id="loslegen-dialog">
. Most likely onclick
.
There are many ways to do this, the way I would personally do it would be to use the dialogOeffnen
function which causes the dialog (popup) to open.
Create span
elements around the data you want to use in your dialog i.e.
<td>
<span id="id_element"><?php echo $row["ID"];?></span><br>
</td>
and
<td>
<span id="title_element"><?php echo $row["Titel"];?></span><br>
</td>
Then ensure you have elements with specific ID attributes where you'd like to display this data i.e.
<h1 id="dialog_title"><?php //echo $row["Titel"]; //You can remove this ?></h1>
Then inside dialogOeffnen
before you display the modal/popup:
document.getElementById("dialog_title").innerText = document.getElementById("title_element").innerText;