Search code examples
phphtml-tablehref

Unable to add multiple url variables inside <td> tag in php


I am trying to show one table row data inside php's tag with some url variables so that when the url is clicked it should open a new page with the 2 url variables passed. But the table data should show the first url variable in assigned but the new page should show both the url variables assigned.

The 2nd variable user will be assigned the next variable read which is incremented by 1 to get the value.

for ($line=0;$line<count($data);$line++)
{
    if($line == 0)
    {
        echo "<td><a target=_blank href=somepage.php?hostname=".$data[$line]."&user= >".$data[$line + 1]."</a></td>";
            }

.... ....

When I use the above code, the table data show the 2nd variable value hyperlinked and on click it is opening another new page with the url as- somepage.php?hostname=my_hostname&user=

So the new page is not getting the 2nd variable value populated after clicked.

I tried many things but it did not solve the issue completely.

Any help or pointers is much appreciated on this. Thanks in advance.


Solution

  • You will need to add single quotes to your href tags but make sure they are different from your string enclosures.

    echo "<td><a target=_blank href='somepage.php?hostname=".$data[$line]."&user=".$data[$line + 1]."'>".$data[$line + 1]."</a></td>";
    

    With the second variable you had your closing tags before the variable.