Solution jcbones Posted March 9, 2013 Solution Share Posted March 9, 2013 Run the following code with NO modifications. When you are sure that it works correctly, then you start modifying it. When it quits working, you will know that what you have tried is wrong. <?php include("colors.php"); function randomColor($colors) { $color = array_rand($colors,1); return (strpos($color,'*') === false) ? substr($colors[$color],1) : randomColor($colors); } // $sql = mysql_query("SELECT * FROM ph_referers WHERE owner = '$_SESSION[username]' ORDER BY id DESC"); // while($row = mysql_fetch_assoc($sql)){ // $ipaddress = $row['ipaddress']; $ipaddress = array('User1' => '127.0.0.1','User2' => '127.0.0.1','User3' => '44.43.44.44', 'User4' => '54.45.45.45'); $usedColors = array(); foreach($ipaddress as $user => $address) { if(array_key_exists($address,$usedColors)) { $color = $usedColors[$address]; } else { $color = randomColor($colors); $usedColors[$address] = $color; } echo '<font color="#' . $color . '">' . $address . '</font><br />'; } //echo "$new - $row[username]:$color<br>"; //} Quote Link to comment https://forums.phpfreaks.com/topic/275423-coloring-usernames-in-table-based-off-ip-address/page/2/#findComment-1417738 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.