0

I have a MYSQL table containing tournament data for players. Each player has stats like games_won, games_lost, etc. I am trying to display this information in a table.

My PHP code looks like this:

//Connecting to $db
//...

//Store table data into array
$result = mysqli_query($db, "SELECT * FROM ladder");

while($row = mysqli_fetch_array($result)) {
echo $row['id'] . " " . <a href=$row['link']$row['username']</a> . " " . $row['tourney_wins'] . " " . $row['game_wins'] . " " . $row['game_losses'] . " " . $row['last_played'];
echo "<br>";

I get an error (Unexpected "<") on

<a href=$row['link']$row['username']</a>

I am trying to display each username in the table as a hyperlink to their respective profile on another site. Can anyone give me a correction? Thanks!

1
  • echo $row['id'] . " " . < <= right there I'll bet. You're missing quotes. Commented Sep 5, 2014 at 15:58

3 Answers 3

1

This is how it should be quoted (assuming I interpreted how you wanted the link properly):

//Connecting to $db
//...

//Store table data into array
$result = mysqli_query($db, "SELECT * FROM ladder");

while($row = mysqli_fetch_array($result))
{
    echo( $row['id']." <a href='".$row['link']."'>".$row['username']."</a> ".$row['tourney_wins']." ".$row['game_wins']." ".$row['game_losses']." ".$row['last_played'] );
    echo("<br>");
}
Sign up to request clarification or add additional context in comments.

Comments

1

Change

<a href=$row['link']$row['username']</a>

to

"<a href=$row['link']$row['username']</a>"

6 Comments

You must quote your HTML php cant interpret <a that's why It gave a syntax error.
Yep that was it, knew it was something with quotes but couldn't remember where they go. Thanks to you and Marc B
One more question...and this one might need a new topic because it's a different problem. But now I'm getting "Parse error: syntax error, unexpected " (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)" on the line we just changed.
Did u closed the HTML at </a>" with a quote ?
I did. ilovecode's submission fixed the Parse error
|
1

You forgot to quote your html:

echo $row['id'] . " " . <a href=$row['link']$row['username']</a> . " " ...snip...
                       ^--here                                  ^--here

Since it's not quoted, PHP is interpreting it <a as concatenate less than undefined constant 'a', which makes no sense.

1 Comment

Also the a tag needs a closing > after the link

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.