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>"; } Link to comment https://forums.phpfreaks.com/topic/78683-solved-need-help-please-should-be-a-quick-easy-one/ 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'] Link to comment https://forums.phpfreaks.com/topic/78683-solved-need-help-please-should-be-a-quick-easy-one/#findComment-398171 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>"; Link to comment https://forums.phpfreaks.com/topic/78683-solved-need-help-please-should-be-a-quick-easy-one/#findComment-398180 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. Link to comment https://forums.phpfreaks.com/topic/78683-solved-need-help-please-should-be-a-quick-easy-one/#findComment-398480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.