0

So I have a dynamic PHP table where I am trying echo one of the table columns as a dynamically generated link. Presently, the $url variable i have declared is returning null. $row['username'] is returning what it should, so I suspect I have the syntax off for that. I also am having trouble with the syntax on the following line. How do I insert the $row['username'] as the link text?

echo "<td>" . "<a href='".$url."'> . $row['username'] .  </a>" . "</td>";

this present example returns an error, but when I replace it with:

echo "<td>" . "<a href='".$url."'> blahblahfiller </a>" . "</td>";

the page runs, so I know it's my syntax there.

Here is my full code for the table:

<?php
   while ($row = mysql_fetch_array($query)) {
        $url = "profilepage.php?name=" + $row['username'];
        echo "<tr>";
        echo "<td>" . '<input type="checkbox" name="checkbox"/>' . "</td>";
        echo "<td>" . "<a href='".$url."'> . $row['username'] .  </a>" . "</td>";
        echo "<td>" . $row['gender'] . "</td>";
        echo "<td>" . $row['username'] . "</td>";
        echo "<td>" . $url . "</td>";
        echo "</tr>";
   }
?>

Sincere thanks for any and all help! It means a lot.

2
  • As you can see on the syntax highlighting $row['username'] is inside the string as you never end it. It needs to be added like gender and the other username (surrounded by " . $row['username'] . ") Commented Nov 6, 2014 at 7:15
  • Thank you. That worked great. I would up vote you, but not enough rep. Commented Nov 6, 2014 at 7:21

1 Answer 1

1

You are using + instead of . for to concatenate. It should be -

$url = "profilepage.php?name=". $row['username'];
Sign up to request clarification or add additional context in comments.

3 Comments

Awesome, thanks so much. That works great. I assumed that worked like HTML for some reason.
HTML or JavaScript?
yeah, Javascript, haha.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.