javascript - 将第一个查询中选定的 id 行传递到第二个查询中使用

标签 javascript php mysql sql

我有一个表,它有一个按钮,可以在其中获取第一个查询中所选行的 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/

相关文章:

javascript - Angular JS : How to get a dynamic input value into ngclick function

javascript - jQuery 元素显示并在按钮单击时向下滑动

javascript - 在javascript中指定图像源

mysql - 在 Rails 中更新计数器,这是否存在并发问题?

javascript - 允许用户将项目放置在循环内的两个不同的可放置区域中

php - PHP traits 会是一个好的解决方案吗

php - Laravel 4.2 中数组到字符串的转换错误

php - Foreach 结果与连接表

php - 阿拉伯语单词上的 MySQL SELECT 在 PHP 上返回 0 结果,但在 SQLBuddy/phpMyAdmin 上返回 0 结果

php - 使用 PHP 在 MySQL 中插入图像时出错