Having a Link Only Appear If a Logged-In User Appears on a Dynamic List
- by John
Hello,
For the function below, I would like the link <div class="footervote"><a href="http://www...com/.../footervote.php">Vote</a></div> to only appear if the logged in user currently appears on editorlist.php. (I. e. if the loginid in the function corresponds to any of the usernames that currently appear in editorlist.php.)
Appearing on editorlist.php is something that is dynamic.
How can I do this?
Thanks in advance,
John
function show_userbox()
{
// retrieve the session information
$u = $_SESSION['username'];
$uid = $_SESSION['loginid'];
// display the user box
echo '<div id="userbox">
<div class="username">'.$u.'</div>
<div class="submit"><a href="http://www...com/.../submit.php">Submit an item.</a></div>
<div class="changepassword"><a href="http://www...com/.../changepassword.php">Change Password</a></div>
<div class="logout"><a href="http://www...com/.../logout.php">Logout</a></div>
<div class="footervote"><a href="http://www...com/.../footervote.php">Vote</a></div>
</div>';
}
On editorlist.php:
$sqlStr = "SELECT
l.loginid,
l.username,
l.created,
DATEDIFF(NOW(), l.created) AS days,
COALESCE(s.total, 0) AS countSubmissions,
COALESCE(c.total, 0) AS countComments,
COALESCE(s.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore,
DATEDIFF(NOW(), l.created) + COALESCE(s.total, 0) * 10 + COALESCE(c.total, 0) AS totalScore2
FROM login l
LEFT JOIN (
SELECT loginid, COUNT(1) AS total
FROM submission
GROUP BY loginid
) s ON l.loginid = s.loginid
LEFT JOIN (
SELECT loginid, COUNT(1) AS total
FROM comment
GROUP BY loginid
) c ON l.loginid = c.loginid
GROUP BY l.loginid
ORDER BY totalScore2 DESC
LIMIT 10";
$result = mysql_query($sqlStr);
$arr = array();
echo "<table class=\"samplesrec1edit\">";
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td class="sitename1edit1"><a href="http://www...com/.../members/index.php?profile='.$row["username"].'">'.stripslashes($row["username"]).'</a></td>';
echo '<td class="sitename1edit2">'.($row["countSubmissions"]).'</td>';
echo '<td class="sitename1edit2">'.($row["countComments"]).'</td>';
echo '<td class="sitename1edit2">'.($row["days"]).'</td>';
echo '<td class="sitename1edit2">'.($row["totalScore2"]).'</td>';
echo '</tr>';
}
echo "</table>";