1

I have made a leaderboard table on my site, which returns the users in the MySQL database with the highest scores (score is a separate field). The fields in the leaderboard table are 'rank' 'username' and 'score'. I would like to link each username in the table to it's own profile page.

The profile pages are in the format /profile.php?user=$username. How would I go about adding an <a href> within the table (which is echoed in PHP):

echo '<tr>
    <td>' .$a. '</td>
    <td><a href="profile.php?user=' .$row['username']. '">' .$row['username']. '</a></td>
    <td>'.$row['count'].'</td>
</tr>'; 

I've tried the above, but it doesn't seem to work. It shows the usernames, but they don't have any hyperlinks.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Taimur
  • 3,171
  • 8
  • 32
  • 38
  • What does the $a variable do? I have tried it in firefox. I have tried it and it works, please tell me what the $a does? – Etienne Marais Jan 07 '11 at 08:04
  • try adding echo ''; before or after the statement. Then look if this it turns up in the output. This looks like you might be editing the wrong file. EDIT: use the magic constants for file and line I can not write the proper syntax in an comment :( – Oliver A. Jan 07 '11 at 08:17

3 Answers3

2
<?php

$row = array(
    'username' => 'Username',
    'count' => 5
);

echo '<table><tr><td>'
    . $a . '</td><td><a href="profile.php?user='
    . $row['username'] . '">'
    . $row['username'] . '</a></td><td>'
    . $row['count'] . '</td></tr></table>';

?>

This works fine, I don't know what the problem is? I just do not know what $a does though

Etienne Marais
  • 1,660
  • 1
  • 22
  • 40
0

Writing

echo '<tr> <td>'. $ a. '</ Td> <td> <a href="profile.php?user=' .$row['username'].'">'. $ Row ['username']. . '</ A> </ td> <td>' $ row ['count'] '</ td> </ tr>'.;

is incorrect because of:

</ A>

Correct version is:

echo '<tr> <td>'. $ a. '</ Td> <td> <a href="profile.php?user=' .$row['username'].'">'. $ Row ['username']. . '</ a> </ td> <td>' $ row ['count'] '</ td> </ tr>'.;
zurfyx
  • 31,043
  • 20
  • 111
  • 145
0

Looks correct to me. I would paste the (html) source-part it outputs, to get a hint what's really going on.

The retrieval part must be good, if you're seeing your usernames, so something strange is going on.

Nanne
  • 64,065
  • 16
  • 119
  • 163