HTML data to PHP


<a data-toggle="modal"> 
data-id="<?php print $row['account_id']; ?>" 
title="Leltár megtekintése&#013;<?php print $row['account_id']; ?>-s azonosító" 
class="open-accountID" 
href="#inventory">
<i class="fa fa-suitcase" aria-hidden="true"></I>
</a>

如何获取数据id并加载到PHP变量?

$player_name = data-id(....)

但是我有两个php文件。变量不在一起。我只需要一个字符id,当我点击一个按钮时,它来自其他PHP文件。

您需要使用Javascript选择数据id并将数据发送到后端。使用fetch或其他ajax方法。

<script>
const element = document.querySelector('.open-accountID');
//console.log(element.dataset.id);
</script>

使用此代码,您将选择数据id属性。我评论了console.log,但用它你可以检查选择是否成功。

如果你想把它发送到php,你必须通过javascript:(无法直接将值获取到php(

1. fetch data-id from the html-element and save it to a variable in javascript
2. send the value of the variable to php 
via ajax or by redirecting to the php with value of the javascript-variable

但你已经有了价值,所以你可以做:

$player_name = $row['account_id'];

最新更新