Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按下按钮时传递动态变量_Php - Fatal编程技术网

Php 按下按钮时传递动态变量

Php 按下按钮时传递动态变量,php,Php,我创建了以下示例代码: // Create connection $conn = Connection(); $result = $conn->query("SELECT * FROM `users` WHERE 1"); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $name= $row[&qu

我创建了以下示例代码:

    // Create connection
    $conn = Connection();

    $result = $conn->query("SELECT * FROM `users` WHERE 1");

  if ($result->num_rows > 0)
  {
    while($row = $result->fetch_assoc())
    {
      $name=  $row["name"] ;
      $id=  $row["id"] ;
      echo "<div class='media text-muted pt-3'>";

      echo "<button class='mr-2 rounded btn-primary icon32 select_c'></button>";

      echo "<p class='media-body pb-3 mb-0 small lh-125 border-bottom border-gray'>";
      echo "<strong class='d-block text-gray-dark'>". $name ."</strong>";
      echo  $id;
      echo "</p>";
      echo "</div>";
    }
//创建连接
$conn=连接();
$result=$conn->query(“从`users`中选择*1”);
如果($result->num_rows>0)
{
而($row=$result->fetch_assoc())
{
$name=$row[“name”];
$id=$row[“id”];
回声“;
回声“;
echo“

”$name.“”; echo$id; 回声“

”; 回声“; }

当使用post方法按下引用按钮时,我想传递id变量。我该怎么做?

您可以在按钮上使用值,然后使用ajax:

echo "<button class='mr-2 rounded btn-primary icon32 select_c' value='".$row["id"]."' onClick='ajaxpost(this)'></button>";

您可以使用按钮上的值,然后使用ajax:

echo "<button class='mr-2 rounded btn-primary icon32 select_c' value='".$row["id"]."' onClick='ajaxpost(this)'></button>";