doulan3436 2015-08-28 14:46
浏览 39
已采纳

POST到PHP弹出窗口的可点击HTML表格行

I have an HTML table that has rows generated with PHP and populated with MySQL data. I want the rows to be clickable, where onclick they open a new window with the MySQL data for that row.

What method can I use to POST a value on click and open the PHP page in a new window without disturbing the parent page? My rows are generated similar to this:

while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
    echo "
        <tr onclick=\"openDetails(" . $row['id'] . ")\"> //openDetails() does nothing for now…
        <td>" . $row['id'] . "</td>
        <td>" . $row['ser'] . "</td>
        <td>" . $row['part'] . "</td>
        <td>" . $row['model'] . "</td>
        <td>" . $row['make'] . "</td>
        <td>" . $row['description'] . "</td>
        <td>" . $row['price'] . "</td>
    </tr>";

openDetails(); does nothing but I thought JS (I'm open to JQuery solutions) was the key. The overall idea is that someone clicks the row and they get assets_details.php (Which will query for WHERE id=$_POST['id'] and populate a form) in a new window where they can edit and submit the information. If POST isn't possible a $_SESSION variable would do, I just don't know how to set either "onclick".

  • 写回答

3条回答 默认 最新

  • douji5397 2015-08-28 16:20
    关注

    Thanks @RamRaider for the suggestions but I know nothing of ajax and I'm afraid to use code that I don't fully understand.

    I came up with this solution though. I wrapped the table in a form and created a hidden input that is set and submitted onclick for the row.

    <form target='_blank' name='getID' method='POST' action='asset_details.php'>
    <input type='hidden' name='id' id='id'>
    <table>
    while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
        echo "
            <tr onclick=\"selectID('" . $row['id'] . "')\">
                <td>" . $row['id'] . "</td>
                <td>" . $row['ser'] . "</td>
                <td>" . $row['part'] . "</td>
                <td>" . $row['model'] . "</td>
                <td>" . $row['make'] . "</td>
                <td>" . $row['description'] . "</td>
                <td>" . $row['price'] . "</td>
            </tr>
    </table>
    </form>";
    

    The JS:

    function selectID(id) {
        document.getID.id.value = $(this).closest('tr').attr('id');
        document.getElementsByName('getID')[0].submit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗