-2

如何使所有成员的用户名显示为蓝色,而不是用户级别为 1 的用户?这是我的代码:

This is the start of the php
 <?php $sql = "SELECT
        topic_id,
        topic_subject
    FROM
        topics
    WHERE
        topics.topic_id = " . mysql_real_escape_string($_GET['id']);

$result = mysql_query($sql);

if(!$result)
{
echo 'The topic could not be displayed, please try again later.';
}
else
{
if(mysql_num_rows($result) == 0)
{
    echo 'This topic doesn&prime;t exist.';
}
else
{
    while($row = mysql_fetch_assoc($result))
    {
        //display post data

        //fetch the posts from the database
        $posts_sql = "SELECT
                    posts.post_topic,
                    posts.post_content,
                    posts.post_date,
                    posts.post_by,
                    users.user_id,
                    users.user_name,
                    users.avatar,
                    users.user_date,
                    users.user_level,
                    users.forum_rank,
                    users.site_rank,
                    users.post,
                    users.signature

                FROM
                    posts
                LEFT JOIN
                    users
                ON
                    posts.post_by = users.user_id
                WHERE
                    posts.post_topic = " .     mysql_real_escape_string($_GET['id']);

        $posts_result = mysql_query($posts_sql);

        if(!$posts_result)
        {
            echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
        }
        else
        {

            while($posts_row = mysql_fetch_assoc($posts_result))
            {

echo ' <br/>';
echo ' <div class="header" id="post11992">

<div class="reply">
    <div class="h3">
        <table class="replyheader">
            <tr>
                <td>
                    <img src="http://www.naruto-boards.com/images/forum/post_reply.gif" alt="" /> Posted on <b>';
                echo '' . date(" F j, Y, g:i A", strtotime($posts_row['post_date'])) . '';echo '</b>
                </td>   
                <td class="right">
<a href="/messages/send/sasy/">Message</a>
<a href="/forums/topic/31/20/quote/11992/#form">Quote</a>
<a href="/forums/topic/31/20/edit/11992/#form">Edit</a>

                </td>
            </tr>
        </table>        
    </div>
</div>
</div>';
echo '<table class="reply">
<tr>
    <td class="post_userinfo">';
///////////webaster
                if($_SESSION['user_level'] != 1 )
{
//the user is not an admin
echo '';
}
else
{ echo '            <a href="/index.php?area=profile&username=' .             $posts_row['user_name'] . '" class="topicuser_member"><font class="rank5">' .     $posts_row['user_name'] . '</font></a>';}

////////////////admin
if($_SESSION['user_level'] != 2 )
{
//the user is not an admin
echo '';
}
else
{ echo '            <a href="/index.php?area=profile&username=' .     $posts_row['user_name'] . '" class="topicuser_member"><font class="rank4">' . $posts_row['user_name'] . '</font></a>';}

////////////////GM
if($_SESSION['user_level'] != 3 )
{
//the user is not an admin
echo '';
}
else
{ echo '            <a href="/index.php?area=profile&username=' .     $posts_row['user_name'] . '" class="topicuser_member"><font class="rank3">' . $posts_row['user_name'] . '</font></a>';}


////////////////Mod
if($_SESSION['user_level'] != 4 )
{
//the user is not an admin
echo '';
}
else
{ echo '            <a href="/index.php?area=profile&username=' . $posts_row['user_name'] . '" class="topicuser_member"><font class="rank2">' . $posts_row['user_name'] . '</font></a>';}

////////////////Member
if($_SESSION['user_level'] != 5 )
{
//the user is not an admin
echo '';
}
else
{ echo '            <a href="/index.php?area=profile&username=' . $posts_row['user_name'] . '" class="topicuser_member"><font class="rank1">' . $posts_row['user_name'] . '</font></a>';}

////////////////guest
if($_SESSION['user_level'] != 0 )
{
//the user is not an admin
echo '';
}
else
{ echo '            <a href="/index.php?area=profile&username=' . $posts_row['user_name'] . '" class="topicuser_member"><font class="rank0">' . $posts_row['user_name'] . '</font></a>';}


echo'
        <br />Rank: ' . $posts_row['site_rank'] . '         <br     />Status: <img style="margin-bottom: -6px; margin-top: -2px;" src="/images/other/1.gif" alt="" /> <span class="online">online</span>            <br /><img style="min-height: 75px; min-width: 75px; max-height: 75px; max-width: 75px;" src="' .     $posts_row['avatar'] . '" alt="" />
        <br /><b>Forum Rank:</b><br />' . $posts_row['forum_rank'] . '              <br /><br /><b>Posts:</b> ' . $posts_row['post'] . '            <br /><b>Joined on:    </b>
        <br />' . date(" F j, Y, g:i A",     strtotime($posts_row['user_date'])) . '        </td>

    <td>
        <div class="post_container">
            <div class="right">
                <br/>
            </div>
            <table>
                <tr>
                    <td class="post_text">

                        ' .     htmlentities(stripslashes($posts_row['post_content'])) . '
                        <div class="dots"></div><div class="signature lock300580">' . $posts_row['signature'] . '</div>
                    </td>
                </tr>
            </table>
        </div>
    </td>
</tr>
</table>
';}}}}}
?>

使用该代码,我可以为网站管理员获取此代码http://prntscr.com/gd5s8 对于访客或任何其他级别,我可以获取此http://prntscr.com/gd5tf

4

4 回答 4

1

据我所知,它是用户名(rank1 等)周围字体标签上的类,因为它似乎是 if 语句块中唯一变化的东西。它根据查看者的用户级别而变化。您可能打算根据 $posts_row 的用户级别对其进行更改。我敢打赌,蓝色样式是基于 rank5 类的,无论是在 css 中还是在某个地方的一些 javascript 中。

如果您想让所有用户名都具有相同的颜色,无论 $posts_row 用户的等级如何,我都建议您去掉 if 语句,因为它们是多余的。

于 2012-09-28T05:26:21.530 回答
1

扩展 Erik 在评论中所说的内容:已经 为元素1rank0提供了.. rank5CSS 类,其中一个已经使(或者是?)元素显示为蓝色!fontrank1rank0

所以改变 CSS就足够了:看看 CSS 是做什么用的rank1(或rank0?),并使其也适用于其他适用的 CSS 类。某处可能涉及到一个 .css 文件,找到它(或适当的内联样式元素)是更改其他关卡玩家名称呈现中使用的颜色的关键,


1弃用<font>标签的这种使用是非常有问题的( HTML5不支持它,自 HTML4.01 以来已弃用!).. 但它可能会继续作为 CSS 绑定站点工作。但是,我建议<span>此时将其更改为(或消除嵌套元素并将类装饰直接添加到<a>)。

于 2012-09-28T05:23:01.510 回答
1

您可以在打印用户名之前使用带有 css 类的跨度,以防除级别 1 之外的所有级别,并为该类提供颜色:蓝色

例如:

 echo '            <a href="/index.php?area=profile&username=' .     $posts_row['user_name'] . '" class="topicuser_member"><font class="rank4"><span class='blue'> . $posts_row['user_name'] . '</span></font></a>';}

而CSS将是

.blue
{
color: blue;
}
于 2012-09-28T05:23:51.720 回答
1

就这样做吧。它很简单:

  $username = $post_row['user_name'];
  if($_SESSION['user_level'] == 1)
  {
       echo "<a style='color: blue;' href='index.php?area=profile&username='$username>$username</a>";
  } 
  else
  {
       echo "<a href='index.php?area=profile&username='$username>$username</a>";
  }

快乐编码:)

于 2012-09-28T06:53:51.643 回答