douguanci9158 2014-10-01 15:57
浏览 32
已采纳

用php数组创建的表。 如何使用jquery获取每个单独的值?

Ok, so I have a page that users upload docs from. I put them in a folder and then update a table to show where these docs live. Now, when I go to an edit page I query that database using PHP and echo the location of those files. I'm trying to figure out a way to delete files. I know I need to unlink, but the problem I'm having is I can't seem to figure out how to get the location of each individual file. Here is the code I'm using to get the file locations.

 <?php

                $sql = 'select trnum, trseq, trfnam, trfloc, podnum
                        from bd.bdvdocs
                        where trnum = ' . $_GET['trnum'];

                $result = db2_exec($conn, $sql);

                if ($result) {
                    while ($row = db2_fetch_array($result)) {


                       echo"<tr>";
                       echo "<td><a href='" . $row[3] . $row[0] . '/' . $row[2] . "'>$row[2]</a>        </td>";


                       echo"</tr>";
                    }
                }

                ?>

This is what I get If I add a button to the right of each link and use jquery to get var, it only comes back with the value of the first link. If I click on the second button the page bombs out.

  • 写回答

1条回答 默认 最新

  • duandi1636 2014-10-01 18:11
    关注

    Give the <td> a class ( echo "<td class = "whatever">... ), create a named table with tbody and stuff and by using jQuerys closest() function you should then be able to find the values:

    $('#name_of_table tbody').on( 'click', 'tr', function () {
           alert($(this).closest('tr').find('.whatever').html());
    });
    

    Create table like:

    <table id="name_of_table"><tbody> 
    

    <?php

    while ($row = db2_fetch_array($result)) {
    
    
                           echo"<tr>";
                           echo "<td class="whatever"><a href='" . $row[3] . $row[0] . '/' . $row[2] . "'>$row[2]</a>        </td>";
    
    
                           echo"</tr>";
                        } ?> </tbody></table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀