duanhui3759 2019-02-21 17:31
浏览 35

仅从数据库中选择最后插入的行

So I have a pop up box that shows when I click on the table row and on that box should be the values from that table row but instead is only showing the last inserted row from db.

Here is the 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;?>

the pop up click on table row is this:

<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";
}
}

db table 1

db table 2

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等