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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题