dqvy87517 2015-01-12 03:00
浏览 35
已采纳

在第一个查询中传递选定的id行以在第二个查询中使用

I have a table and it has a button where it would get the ID of the selected row in the first query :

echo "
<td>
    <a type='button' id='seemore' data-toggle='modal' idNum='".$row['marriage_id']."' 
      data-target='#see_more'> 
      </a> 
</td>";

The idNum='".$row['marriage_id']."' is equal to the ID number of that row. I want to use idNum='".$row['marriage_id']."' in my second query as my WHERE clause.

This is what I currently have:

 SELECT * FROM marriage WHERE marriage_id = idNum
  • 写回答

1条回答 默认 最新

  • duanmu3049 2015-01-12 05:00
    关注

    If i understood correctly, you want to access the value of ID which can be used as a parameter for DB query. You can learn more about my implementation in jQuery with this link CreateEvent

    You have mentioned that, on button click, you are getting the 'ID' of the selected row

    "..it has a button where it would get the ID of the selected row in the first query"

    And you want this ID to be appended as

    SELECT * FROM marriage WHERE marriage_id = ID

    as a DB query to some server, then Add below line of codes in the event listener of button click:

    //event listener for button clicked
    $('#btn').on('click', function(e){
        //var id;
        //Your logic to get the ID of the selected row and assign it to variable id 
        var e = $.Event( "build" );
        //Trigger the custom event along with the id as data to be passed
        $(this).trigger(e,[id] );
    });
    

    Now only thing left for you is to add a listener for the custom event generated, i.e. 'build'. Add that listener to the table (assuming its id-- 'tbl') and follow this:

     $('#tbl').on('build', function(e, param){
        //param is the ID of the selected row. In here you can perform XHR providing ID as parameter
         //alert(param);
     });
    

    Hope that helps to resolve the problem you are facing now!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题