dongzhimin2231 2018-08-07 15:06
浏览 92

如何在每次单击按钮然后使用它进行查询时获取php变量?

I`am trying to get the $row['username'] every time I click on the button, for me to use it in the query . But only the first array is displayed. I want to use jquery but I have small knowledge on it.

<?php
  $query = $con->query("SELECT * FROM account WHERE acc = 'agency'");
  while($row = mysqli_fetch_array($query))
  {
    echo $row['username'];
  ?>
    <button data-target="#select" data-toggle="modal">Select</button>
<?php } ?>


  <div class="modal" id="select">
  <?php
    $query = $con->query("SELECT * FROM sample WHERE username = ".$row['username']."");

  ?>
  • 写回答

1条回答 默认 最新

  • duanmeng3476 2018-08-07 15:24
    关注
    <button id="select"
            class="selectUser"
            data-username="<?php echo $row['username']; ?>"
            data-toggle="modal"
            data-target="#select">Select</button>
    

    I took the html you put in your comment, and added a class to it. Now all you need to do is create your javascript binding for it.

    //find all the buttons with the selectUser class and bind a click handler to them
    $('.selectUser').on('click', function(e){
        //turn the element into a jQuery object so we can use jQuery methods
        var $selectUser = $(this);
        //log the username data attribute from the button
        console.log($selectUser.data('username'));
    
        //you could also get the attribute without jQuery
        console.log(this.getAttribute('data-username'));
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看