0

所以我在我的网站上有一个历史记录,我想从单击的行中获取值并仅针对该行 ID 显示它们。我有这个表格,但是当我单击每一行时,它会为不同的行显示相同的值,例如这个

HTML 代码:

<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; ?>

这是js代码:

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

这是php代码:

<?php
print_r($_POST);
$idoc = isset($_POST['idoc']) ? $_POST['idoc'] :  1;                        
echo  $idoc;
$query =  "SELECT * FROM ocorrencia where id=$idoc";
echo $query;
$result1 = mysqli_query($conn, $query);                     
while ($row = mysqli_fetch_assoc($result1)): ?>
    <p class="data"><?php echo $row['data']; ?></p>
    <p class="sala"><?php echo $row['sala']; ?></p>
    <textarea readonly id="descricao"><?php echo $row['descricao'];?></textarea>
<?php endwhile; ?>
4

0 回答 0