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