我的问题是我想在循环中为每个$ i增量创建一个按钮,并且在单击一个按钮时,我必须调用另一个PHP文件的包含,但是将参数(链接)传递给包括PHP。 所以这就是我的尝试:
for($i=0;$i<64;$i++){
$link="https://www.google.fr/search?q=$i"; //for example
echo '
<form method="post">
<button name="button$link">Hello</button>
</form>';
// generate random string to have random variable name (unique)
$seed = str_split('abcdefghijklmnopqrstuvwxyz'.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.'0123456789');
shuffle($seed);
$rand = '';
foreach (array_rand($seed, 5) as $k){
$rand .= $seed[$k];
}
$$rand=$link; //puts the parameter (link) in the dynamic variable
if(isset($_POST["button$$rand"])){
include("other.php"); // $$rand is used in that function
}
}
所以我尝试使用动态变量,但作为检查按钮是否被点击的部分&#39;它的工作不在循环中,我无法获得正确的按钮名称。
答案 0 :(得分:0)
我设法找到了解决方案! 我用过ajax。 所以在每个按钮上都有一个调用ajax函数,你可以将参数传递给ajax函数(在我的例子中是一个链接)
它应该是这样的:
<button onclick="function('parameter')">