loops - PHP buttons in 'for' and onclick with parameter -
my problem want make 1 button each $i incrementation in loop, , on click of 1 button, must call include of php file, passing parameter (a link) included php. here have tried:
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 have random variable name (unique) $seed = str_split('abcdefghijklmnopqrstuvwxyz'.'abcdefghijklmnopqrstuvwxyz'.'0123456789'); shuffle($seed); $rand = ''; foreach (array_rand($seed, 5) $k){ $rand .= $seed[$k]; } $$rand=$link; //puts parameter (link) in dynamic variable if(isset($_post["button$$rand"])){ include("other.php"); // $$rand used in function } }
so tried dynamic variables, part 'checks if button clicked' job out of loop, cannot right button name.
i have managed find solution ! used ajax. on every button there call ajax function, , can pass parameter ajax function (a link in case)
it should this:
<button onclick="function('parameter')">
Comments
Post a Comment