2010-06-08 70 views
0

对于以下功能,我希望链接<div class="footervote"><a href="http://www...com/.../footervote.php">Vote</a></div>仅在登录用户当前出现在editorlist.php上时才会显示。 (一e。如果在功能上loginid对应于任何目前出现在editorlist.php的username S的。)如果登录用户出现在动态列表中,仅显示链接

浮出editorlist.php的东西是动态的。

我该怎么做?

由于提前,

约翰

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>'; 
} 

在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>"; 

回答

0

你可以尝试从editorlist.php运行SQL查询,以确定用户是否在名单上而不是试图从editorlist.php页面本身提取数据。

0

我会让你的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 
} 

和show_userbox(),你可以做

$editor = getEditors(12); 
if($editor) { 
    // echo your vote html stuff 
} 

我不是说这样做隐含..但我认为它会给你正确的想法,从...跳转。

0

如果用户在整个站点中被列为编辑器,我建议设置一个$_SESSION[]变量来记录用户是否是编辑者,同时处理他们的登录。

如果编辑受限于他们的控制权,可能将会话变量设置为可编辑的项目数组可能是一个选项。

只是想 - 检查一次,记住,而不是检查每一个。单。时间。

相关问题