widget Posted November 24, 2007 Share Posted November 24, 2007 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>"; } Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 24, 2007 Share Posted November 24, 2007 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'] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 24, 2007 Share Posted November 24, 2007 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>"; Quote Link to comment Share on other sites More sharing options...
widget Posted November 25, 2007 Author Share Posted November 25, 2007 Thank you so much wildteen88!!!! It works perfectly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.