gpt4 book ai didi

php - 将变量作为 传递给模态,然后需要在 SQL 查询中使用解析后的变量

转载 作者:行者123 更新时间:2023-11-29 15:18:18 28 4
gpt4 key购买 nike

非常感谢您提供的所有帮助。

我正在将 data-id 值传递给引导模式表单。 data-id 是从 while 循环生成的。这是循环内的行...

echo "<div class='col-2'><a href='' data-toggle='modal' data-target='#modaleditprice' class='btn btn-primary btn-sm' data-id='".$bids['PriceID']."'><i class='far fa-edit'></i></a></div>";

然后我有一些 jquery 将数据发送到模态表单...

$('#modaleditprice').on('show.bs.modal', function (e) {
var SentPriceID = $(e.relatedTarget).attr('data-id');
$(this).find('.ModalPriceID').text(SentPriceID);
});

最后,这是模式表单本身内的 php 和 html 代码...

$PriceID = "<span class='ModalPriceID'></span>";
$priceSQL = "SELECT * FROM prices WHERE PriceID = ".$PriceID;
$priceQRY = $conn->query($priceSQL);

...

<div class="modal-header">
<h4 class="modal-title">Edit Price - <?php echo $PriceID; ?></h4>
<button type="button" class="close" data-dismiss="modal" aria label="Close">
<span aria-hidden="true">×</span>
</button>
</div>

<div class="modal-body">
<form method="POST" action="editprice.php">
etc...

该表单使用从 SQL 查询检索到的值进行填充。如果我能让 SQL 查询工作,那么表单就可以正常工作...问题是我无法在 php 段中成功解析上面的查询。 html 段呈现 $PriceID 的正确值,即它首先呈现为 span 代码,然后在 html 加载完成后显示正确的价格 ID 值。但我需要事先使用它作为解析变量。有什么想法吗?

编辑:我正在使用两个 php 文件,这可能是这里的问题,即我根据主文件中的条件包含模式文件...

if (isset($_SESSION['UserRole']) && ($_SESSION['UserRole'] == 'Trader' || $_SESSION['UserRole'] == 'Viewer'))   {
// Proceed if Viewer or Trader else boot out
include_once '../../'.$config["paths"]["secured"].'pricemodals.php';

最佳答案

看起来您的 sql 语句将解析为以下内容

SELECT * FROM prices WHERE PriceID = <span class='ModalPriceID'></span>;

因为您是 $PriceID 的字符串而不是引用。页面渲染后,您似乎还尝试在 php 中对页面执行操作。您需要在模式中创建一个小表单,将值作为表单数据发送,例如 $_POST/$_GET,其中页面将基本上刷新并处理页面顶部的那些项目(如果存在), https://www.w3schools.com/php/php_forms.asp

或者更好的是使用 AJAX 异步发送查询并在不加载页面的情况下对响应使用react。 https://www.w3schools.com/jquery/jquery_ref_ajax.asp

关于php - 将变量作为 <span> 传递给模态,然后需要在 SQL 查询中使用解析后的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59536006/

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