我有一个表,它有一个按钮,可以在其中获取第一个查询中所选行的 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 值。您可以通过此链接 CreateEvent 了解有关我在 jQuery 中实现的更多信息
您已经提到,单击按钮时,您将获得所选行的“ID”
"..it has a button where it would get the ID of the selected row in the first query"
并且您希望将此 ID 附加为
SELECT * FROM marriage WHERE 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);
});
希望能帮助您解决目前遇到的问题!
关于javascript - 将第一个查询中选定的 id 行传递到第二个查询中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27894711/