douzongmu2543 2019-04-19 06:43
浏览 168
已采纳

在php中获取span标签的值并在sql语句中部署,不起作用

I have a little problem in my code, please review it and help me. I want to assign value of the span tag(fetched by id in html) to a php variable and then run a sql query to fetch record of the related value in the table. Here is my code.

I tried it in different ways but it not works. I print the sql query and its absolutely right but does not show the correct result. I copied that printed sql query and paste it into phpmyadmin query section and run it there. Then it works fine and show related records. Please help

$regg = '<span id="modal-myvalue"></span>';
$fee_detail = "SELECT * FROM `fee_enroll` WHERE registeration = '$regg' AND mode = 'ENABLE'";
//here i print the query and its output is correct but doesn't show the correct record here.      
echo $fee_detail;
 $result_fee = mysqli_query($con, $fee_detail);
 while($row_fee = mysqli_fetch_assoc($result_fee)) {
 echo $row_fee['registeration'];
 }

The data which i want to fetch in span tag(in id) is sent from a button through this script:

<script type="text/javascript">    
    var ATTRIBUTES = ['myvalue'];
    $('[data-toggle="modal"]').on('click', function(e) {
        var $target = $(e.target);
        var modalSelector = $target.data('target');

        ATTRIBUTES.forEach(function(attributeName) {
            var $modalAttribute = $(modalSelector + ' #modal-' + attributeName);
            var dataValue = $target.data(attributeName);

            $modalAttribute.text(dataValue || '');
        });
    });
</script>

and the button code is

<a class="btn" type=submit data-toggle="modal" data-target="#model-view" data-myvalue="<?php echo $row['registeration']; ?>">VIEW Detail</a>

When i print the query it shows:

(SELECT * FROM `fee_enroll` WHERE registeration = 'FA12-BSE-094' AND mode = 'ENABLE')

which works correctly in phpmyadmin query section. but not works here when i want to execute.

  • 写回答

2条回答 默认 最新

  • dqdl6469 2019-04-19 07:10
    关注

    You can try DOMDocument as follows,

    $regg = '<span id="modal-myvalue">FA12-BSE-094</span>';
    $doc = new DOMDocument();
    $doc->loadHTML($regg);
    $elements = $doc->getElementsByTagName('span')->item(0);
    var_dump($elements->nodeValue);
    

    And then you can use this variable in query like below,

    $fee_detail = "SELECT * FROM `fee_enroll` WHERE registeration = '$elements->nodeValue' AND mode = 'ENABLE'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题