Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
如何使用HTML链接传递多个PHP变量而不刷新页面?_Php_Variables_Dynamic_Hyperlink - Fatal编程技术网

如何使用HTML链接传递多个PHP变量而不刷新页面?

如何使用HTML链接传递多个PHP变量而不刷新页面?,php,variables,dynamic,hyperlink,Php,Variables,Dynamic,Hyperlink,我有一些代码: $page = $_GET['page']; 然后我想调用index.php?页面中的另一个页面= if($page == "view_data") { include "view_data.php"; } else if($page == "edit_data") { include "edit_data.php?id="; } else if($page == "delete_data") { include "delete_data.php?id="; }

我有一些代码:

$page = $_GET['page'];
然后我想调用index.php?页面中的另一个页面=

if($page == "view_data") 
{
  include "view_data.php";
}
else if($page == "edit_data")
{
  include "edit_data.php?id=";
}
else if($page == "delete_data")
{
  include "delete_data.php?id=";
}
else
{
  echo "Cannot found the page";
}
然后,我创建一个链接,生成上面的
if
函数

<a href="index.php?page=edit_data&id=<?= $row['id_data'] ?>">Edit</a>
<a href="index.php?page=delete_data&id=<?= $row['id_data'] ?>">Delete</a>


我的问题是,如果我必须在链接中使用两个变量,以便编辑和删除数据只能执行一个页面,那么如何传递编辑数据或删除数据?

我建议在客户端使用
ajax

function doAction(page,id)
{
  var xmlhttp=new XMLHttpRequest();

  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
        var response=xmlhttp.responseText;
        alert(response);//if you want to notify the user that the job was done successfully
      }
    }
    xmlhttp.open("GET","index.php?page="+page+"&id="+id,true);
    xmlhttp.send();
  }
}
您的HTML将使用
onClick
属性

<button onclick="<?php echo "doAction(\"edit_data\",".$row['id_data'].")"; ?>">Edit</button>
<button onclick="<?php echo "doAction(\"delete_data\",".$row['id_data'].")"; ?>">Data</button>

请澄清:您希望仅使用一个链接通过
页面
编辑_数据
删除_数据
,并使您的脚本包含edit_data.php和delete_data.php?根据数据ID,仅使用一个包含多个数据的链接,在同一迭代中编辑和删除数据的结果如何?如果先编辑,则会将其删除。如果先删除,则将没有任何内容可编辑。