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

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']

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.