因此,我有一个弹出框,当我单击表行时显示该框,该框应为该表行中的值,而仅显示db中最后插入的行。
这是HTML:
<tbody>
<?php
$conn = mysqli_connect("localhost", "root", "", "fix_in_time");
$result = mysqli_query($conn, "SELECT * FROM `ocorrencia` as o INNER JOIN
`insere_material` as im ON o.id = im.id");
$num = 1;
while($row = mysqli_fetch_assoc($result)):
?>
<tr id="table_row_<?php echo $num; ?>" onclick="hide('table_row_<?php echo
$num; ?>'), window.location= '#bg'">
<td style="font-family: Arial; font-size: 17px;"><?php echo $row['data']; ?>
</td>
<td style="font-family: Arial; font-size: 17px;"><?php echo $row['sala']; ?>
</td>
<td style="font-family: Arial; font-size: 17px;"><?php echo $row['tipo']; ?>
</td>
</tr>
<?php endwhile; ?>
<script src="scripts/table.js"></script>
<div id="bg"></div>
<div class="box">
<a href="" id="close">X</a>
<p id="rcorners1"></p>
<p id="Title1">Data</p>
<p id="Title2">Sala</p>
<p id="Title3">Tipo</p>
<p id="Title4">Descrição</p>
<?php
$result1 = mysqli_query($conn, "SELECT * FROM `ocorrencia` as o INNER JOIN `insere_material` as im ON o.id = im.id");
while ($row = mysqli_fetch_assoc($result1)): ?>
<p class="data"><?php echo $row['data']; ?></p>
<p class="sala"><?php echo $row['sala']; ?></p>
<p class="tipo"><?php echo $row['tipo']; ?></p>
<textarea readonly id="descricao"><?php echo $row['descricao'];?></textarea>
<?php endwhile;?>
在表格行上单击弹出框是
<tr id="table" onclick="hide(), window.location= '#bg'">
<td style="font-family: Arial; font-size: 17px;"><? php echo $row['data']; ?
></td>
<td style="font-family: Arial; font-size: 17px;"><?php echo $row['sala']; ?>
</td>
<td style="font-family: Arial; font-size: 17px;"><?php echo $row['tipo']; ?>
</td>
</tr>
JS:
function hide(tableRow){
var x = document.getElementById(tableRow);
if(x.style.display === "none"){
x.style.display = "block";
}else{
x.style.display = "none";
}
}