如何在PHP文件内的MySQL查询中使用Javascript声明的变量

如何在PHP文件内的MySQL查询中使用Javascript声明的变量,javascript,php,mysql,Javascript,Php,Mysql,我正在尝试访问我的URL的一部分,以便在MySQL脚本中使用,在该脚本中,结果将在站点上的点上使用 下面的脚本允许我访问与URL关联的ID字符串(格式为://localhost/example/examplepage.php#1911)-在这种情况下为我提供了“1911”: <script> function getPlayer() { var playerID = window.location.hash.substring(1); document.g

我正在尝试访问我的URL的一部分,以便在MySQL脚本中使用,在该脚本中,结果将在站点上的点上使用

下面的脚本允许我访问与URL关联的ID字符串(格式为://localhost/example/examplepage.php#1911)-在这种情况下为我提供了“1911”:

<script>
  function getPlayer() {
      var playerID = window.location.hash.substring(1);
      document.getElementById("playerID").innerHTML = playerID;
    }
</script>

函数getPlayer(){
var playerID=window.location.hash.substring(1);
document.getElementById(“playerID”).innerHTML=playerID;
}
我想使用1911并在同一个.php文件中的MySQL查询中使用它。我有以下疑问:

<?php 
  mysqli_set_charset($conn,"utf8");
  $sql = "SELECT * FROM players WHERE id = 34";
  $result = mysqli_query($conn, $sql); 
?>

球员是我的查询表。当我在这里硬编码一个数字(34)时,这本身就起作用了。我希望能够根据前面声明的playerID变量实现动态


我该怎么做?

您需要向PHP发出请求。你听说过AJAX吗?