1

I have foreach:

foreach( $playerHouses as $house ) :
    echo "<tr><th>$house[id]</th><td>$house[houseNumber]</td></tr>";
endforeach;

And I want to make button with href a href="myfile.php?v=houses&id[]=1&id[]=2" (1,2) house id, foreach..

How can I do this? Now I have

echo "<a href='myfile.php?v=houses'>click me</a>";
3
  • "One more question" - That'd make the question too broad. Let's start by fixing one, then post another question afterwards, or edit your post to contain what you tried. Edit: this comment as per the original post stackoverflow.com/revisions/45904895/1 Commented Aug 27, 2017 at 12:24
  • 2
    Possible duplicate of Generate URL with parameters from an array Commented Aug 27, 2017 at 12:31
  • The question seems to be a bit ambiguous. Do you mean that value relevant to the all of the ids should be passed in one go? Commented Aug 27, 2017 at 12:34

2 Answers 2

2

@Amid Kumar is almost there, but I understand OP wanted id to be passed as an array. Therefore his answer should be modified to

$url = "myfile.php?v=houses";
foreach ($playerHouses as $value)
{
    $url .= '&id[]='.$value['id'];
}
Sign up to request clarification or add additional context in comments.

Comments

0

do something like this:

    $url = "myfile.php?v=houses";
foreach ($playerHouses as $key => $value)
{
        $url .= '&id='.$value['id'];
}

4 Comments

As a result only last id will be passed.
for each loop $url will be concatenated with '&id='.$value['id'] and the finally becomes like: $url = myfile.php?v=houses&id=1&id=2&id=3&id=4
And when user clicks this link $_GET[id] will be 4.
Yes you are right but from the question posted above, its appear that the question owner is concerned only about string for url that my code gives, so I addressed only that. No where he mentioned about $_GET

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.