Your foreach loop seems to work properly if you get the id=2&id=1
in your browser query using method=get
. I think you have to understand HTML forms first to realize your problem here.
With your code above you are generating a form with an array of ids:
<form action='aaa.php' method='get'>
<input type="hidden" name="id" value="2">
<input type="hidden" name="id" value="1">
<input type="submit" name="Action" value="View"/>
</form>
But actually you want to send one id at a time. So you have to generate multiple forms to achieve this:
<form action='aaa.php' method='get'>
<input type="hidden" name="id" value="2">
<input type="submit" name="Action" value="View"/>
</form>
<form action='aaa.php' method='get'>
<input type="hidden" name="id" value="1">
<input type="submit" name="Action" value="View"/>
</form>
I hope, now you understand the point.
To solve your problem, your PHP code should be like so:
foreach ($a as $b)
{
echo "<form action='aaa.php' method='get'>
<input type="hidden" name="id" value=" . $b['id'] . ">
<input type="submit" name="Action" value="View"/>
</form>";
}
1
solved foreach in form not working properly [closed]