gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 16:05:43 25 4
gpt4 key购买 nike

我的代码有一点问题,请检查它并帮助我。我想将span标签的值(通过html中的id获取)分配给php变量,然后运行sql查询来获取表中相关值的记录。这是我的代码。

我尝试了多种方法,但没有成功。我打印了 sql 查询,它绝对正确,但没有显示正确的结果。我复制了打印的 sql 查询并将其粘贴到 phpmyadmin 查询部分并在那里运行。然后它就可以正常工作并显示相关记录。请帮忙

$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'];
}

我想在span标签中获取的数据(在id中)是通过此脚本从按钮发送的:

<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>

按钮代码是

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

当我打印查询时,它显示:

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

它在 phpmyadmin 查询部分正常工作。但当我想执行时在这里不起作用。

最佳答案

您可以尝试DOMDocument如下,

$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);

然后您可以在查询中使用此变量,如下所示,

$fee_detail = "SELECT * FROM `fee_enroll` WHERE registeration = '$elements->nodeValue' AND mode = 'ENABLE'";

关于php - 在php中获取span标签的值并在sql语句中部署,不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55757655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com