从点击的表格行中获取ID并显示该行的值

时间:2019-04-11 14:40:40

标签: php jquery

因此,我在网站上有一个历史记录,我想从单击的行中获取值,并仅针对该行ID显示它们。我有this表,但是当我单击每一行时,它为this

等不同行显示了相同的值

HTML代码:

std::valarray

这是js代码:

<table style="width:100%" id="listagem">
<thead>
<tr>
    <th style="font-family: Arial; font-size: 20px;">Data</th>                           
    <th style="font-family: Arial; font-size: 20px;">Sala</th> 
    <th style="font-family: Arial; font-size: 20px;">Tipo</th>
</tr>
</thead>
<tbody>
<?php
$result = mysqli_query($conn, "SELECT * FROM `ocorrencia` as o ORDER BY 
o.data DESC");
while($row = mysqli_fetch_assoc($result)): ?>
    <tr id="tr" onclick="hide(), window.location = '#bg'">
        <td idlista="<?php echo $row['id']; ?>" style="display:visible;font-family: 
Arial; font-size: 12px;"><a><?php echo $row['id']; ?></a></td>
        <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
$result_t = mysqli_query($conn, "SELECT m.tipo 
                            FROM `material` as m 
                            INNER JOIN `ocorrencia_detalhe` as od on m.id = od.id_tipo 
                                AND od.id_ocorrencia=".$row['id']);
while ($row2 = mysqli_fetch_assoc($result_t)): ?>
    <?php echo $row2['tipo'] . " "; ?>
<?php endwhile;?>                                       
</td>
</tr>
<?php endwhile; ?>

这是php代码:

var idocorrencia;
$(document).on("click","#listagem tr", function(e){
    e.preventDefault();
    idocorrencia = $(this).parent().attr("idlista");
    $("#listagem caption").text($(this).text());
    $.post( "historico.php", { idoc: idocorrencia })
});                         

0 个答案:

没有答案