Jump to content

[SOLVED] Need help please - should be a quick easy one


widget

Recommended Posts

Hi, When i do an IP check on my website to search for matching users I want it to display the users status next to the name but its not working properly. Could someone please take a look at my code and tell me what Im doing wrong?

 

Thank you

 

	$x = 0;
while ($getQuery = mysql_fetch_array($query))
{
	$x++;
	$findUser = fetch("SELECT * FROM members2 WHERE id = '$getQuery[userid]'");
        $rank1 = $findUser[rank];

if ($rank1 = "0")
{
$rank =  "<font color=red>Suspended</font>";
}
if ($rank1 = "1")
{
$rank =  "<font color=red>Logged In - No Rank</font>";
}
if ($rank1 = "2")
{
$rank =  "<font color=red>Under 13</font>";
}
if ($rank1 = "3")
{
$rank =  "<font color=red>Regular User</font>";
}
else
{
$rank =  "<font color=green>Staff</font>";
}

	$results .= "$x. $findUser[username] - $getQuery[ip_addr] - $rank<br>";
}

print "<p>$x results found.</p><p>$results</p>";
}

Link to comment
Share on other sites

Try changing to:

 

	$x = 0;
while ($getQuery = mysql_fetch_array($query))
{
	$x++;
	$findUser = fetch("SELECT * FROM members2 WHERE id = '$getQuery[userid]'");
        $rank1 = $findUser['rank'];

if ($rank1 == "0")
{
$rank =  "<font color=red>Suspended</font>";
}
if ($rank1 == "1")
{
$rank =  "<font color=red>Logged In - No Rank</font>";
}
if ($rank1 == "2")
{
$rank =  "<font color=red>Under 13</font>";
}
if ($rank1 == "3")
{
$rank =  "<font color=red>Regular User</font>";
}
else
{
$rank =  "<font color=green>Staff</font>";
}

	$results .= "$x. $findUser['username'] - $getQuery['ip_addr'] - $rank<br>";
}

print "<p>$x results found.</p><p>$results</p>";
}

 

 

Notice the == double equal sign when checking if ($rank1 == "1")?

 

Also, I changed your array vars and added single quotes.. from $findUser[username] to $findUser['username']

Link to comment
Share on other sites

Those if statements would be better of being a switch/case also did a few fixes in your code.

    $x = 1; $results = null;
while ($getQuery = mysql_fetch_array($query))
{
	$findUser = fetch("SELECT * FROM members2 WHERE id = '{$getQuery['userid']}'");

        switch($findUser['rank'])
        {
            case '0':
                $color = 'red';
                $text  = 'Suspended';
            break;

            case '1':
                $color = 'red';
                $text  = 'Logged In - No Rank';
            break;

            case '2':
                $color = 'red';
                $text  = 'Under 13';
            break;

            case '3':
                $color = 'red';
                $text  = 'Regular User';
            break;

            default:
                $color = 'green';
                $text  = 'Staff';
            break;
        }

        $rank = '<font color="' . $color . '">' . $text . '</font>';

	$results .= "$x. {$findUser['username']} - {$getQuery['ip_addr']} - $rank<br>";

        $x++;
}

print "<p>$x results found.</p><p>$results</p>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.