Php 只有当登录用户出现在动态列表中时,才会显示链接
对于下面的函数,我希望该链接仅在登录用户当前出现在editorlist.php上时出现。即。如果函数中的loginid对应于当前出现在editorlist.php中的任何用户名 出现在editorlist.php上是动态的 我该怎么做 提前感谢, 约翰 在editorlist.php上:Php 只有当登录用户出现在动态列表中时,才会显示链接,php,mysql,Php,Mysql,对于下面的函数,我希望该链接仅在登录用户当前出现在editorlist.php上时出现。即。如果函数中的loginid对应于当前出现在editorlist.php中的任何用户名 出现在editorlist.php上是动态的 我该怎么做 提前感谢, 约翰 在editorlist.php上: $sqlStr = "SELECT l.loginid, l.username, l.created, DATEDIFF(NOW(), l.created) AS days
$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>";
您可以尝试从editorlist.php运行SQL查询以确定用户是否在列表中,而不是尝试从editorlist.php页面本身提取数据。我会使您的编辑器SQL更易于管理,例如:
function getEditors($editor = false) {
$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 ";
if( $editor !== false ) { //if we specified an editor, find it
$sqlStr .= " WHERE `l.loginid` = '" . $editor . "'";
}
$sqlStr .= "GROUP BY l.loginid
ORDER BY totalScore2 DESC
LIMIT 10";
$result = mysql_query($sqlStr);
if( $editor !== false) { // if we specified an editor, return that editor or false
if( $row = mysql_fetch_assoc($result)) {
return $row;
}
return false;
}else { // otherwise, return the array of editors
$editors = array();
while( $row = mysql_fetch_assoc($result)) {
$editors[] = $row;
}
return $editors;
}
}
对于editorlist.php,您可以这样做
$editors = getEditors();
foreach( $editors as $editors ) {
// echo your table row like you were doing
}
$editor = getEditors(12);
if( $editor ) {
// echo your vote html stuff
}
在show_用户框中,您可以
$editors = getEditors();
foreach( $editors as $editors ) {
// echo your table row like you were doing
}
$editor = getEditors(12);
if( $editor ) {
// echo your vote html stuff
}
我不是说要含蓄地这么做。。但我认为它会让您正确地了解从何处跳转。如果一个用户在整个网站中被列为编辑,我建议设置一个$\u SESSION[]变量,在您处理其登录时记录该用户是否为编辑 如果编辑器在控制方面受到限制,那么可以选择将会话变量设置为可以编辑的项目数组 只是思考——检查一次并记住,而不是每次都检查。仅有一个的时间