开发者

Hyperlinks within a table - '<a href="">'.$row['username'].'</a>'

开发者 https://www.devze.com 2023-02-03 04:38 出处:网络
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\' \'userna

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 s开发者_如何学Pythonhows the usernames, but they don't have any hyperlinks.


<?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


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.


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>'.;
0

精彩评论

暂无评论...
验证码 换一张
取 消