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


Passing the selected id row in the first query to be used in the second query

我有一个表,它有一个按钮,它将在其中获取第一个查询中所选行的ID

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

idNum='".$row['marriage_id']."'等于该行的ID号。我想在第二个查询中使用idNum='".$row['marriage_id']."'作为我的WHERE子句。

这是我目前拥有的:

 SELECT * FROM marriage WHERE marriage_id = idNum

如果我理解正确,您希望访问 ID 的值,该值可用作数据库查询的参数。你可以通过这个链接了解更多关于我在jQuery中的实现 创建事件

您提到,单击按钮时,您将获得所选行的"ID"

"..它有一个按钮,它将在第一个查询中获取所选行的 ID"

并且您希望将此 ID 追加为

从婚姻中选择 *,其中 marriage_id = ID

作为对某个服务器的数据库查询,然后在按钮单击的事件侦听器中添加以下代码行:

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

现在,您唯一要做的就是为生成的自定义事件添加一个侦听器,即"构建"。将该侦听器添加到表中(假设其 id-'tbl'),然后遵循以下内容:

 $('#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);
 });

希望这有助于解决您现在面临的问题!