L Posted December 10, 2007 Share Posted December 10, 2007 Hey, I have different users with reputation points..and with more points the higher number of boxes you get near your name But they're dif. colored boxes(light green and dark green [good]) (red and then pink [bad rep]) So if I take, $num_images = $total_rep_of_user/150 but now how do I make it so it displays $num_images boxes progressing with the first five being light green and then later five being dark green. Or first five being pink then last 5 being red. I have an idea about the different color thing with if statements, but I don't know how I'd echo $num_images of boxes Thanks, I hope I was clear. edit Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/ Share on other sites More sharing options...
JacobYaYa Posted December 10, 2007 Share Posted December 10, 2007 for($i =0; $i <= $num_boxes; $i++){ if($i > 5){ //Output your 6-10 box image here }else{ //Output your 1-5 box image here } } Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410708 Share on other sites More sharing options...
L Posted December 10, 2007 Author Share Posted December 10, 2007 Thanks, this is how I modded it. for($i =0; $i <= $num_haros; $i++){ if($i < 10 && $i > 5){ echo "<img src=\"/images/harolgreen.PNG\" alt=\"\" />"; }elseif ($i < 5 && $i > 0){ echo "<img src=\"/images/harogreen.png\" alt=\"\" />"; } elseif($i < 0 && $i > -5) { echo "<img src=\"/images/haropink.png\" alt=\"\" />"; } elseif($i > -10 && $i < -5) { echo "<img src=\"/images/haro1pink.PNG\" alt=\"\" />"; } } But when $num_haros is a negative value it doesn't seem to work...any way how to fix it? Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410753 Share on other sites More sharing options...
BillyBoB Posted December 10, 2007 Share Posted December 10, 2007 can i see some of the coding maybe farther up like where you set the $num_haros Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410759 Share on other sites More sharing options...
L Posted December 10, 2007 Author Share Posted December 10, 2007 $rep_images = mysql_query("SELECT `rep` FROM `users` WHERE `userid`='".$posts['by']."''", $conn); $touser = mysql_fetch_array($rep_images); $num_haros = $touser['rep']/225; then the for statment... posts['by'] is the while for fetching all the posts in the thread... When the rep is positive it shows up fine, but when it's negative nothing shows. Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410762 Share on other sites More sharing options...
BillyBoB Posted December 10, 2007 Share Posted December 10, 2007 Since dividing a negative one by two is the same as dividing a positive one by two with the exception of the negative. Just see it if it positive or negative. if($num_haros<0) { $comment = "negative"; $num_haros = $num_haros * -1; } Then use the info to do the for statement and use the $comment to see if it is a negative or not. Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410765 Share on other sites More sharing options...
L Posted December 10, 2007 Author Share Posted December 10, 2007 Thanks for the idea. This is basically what I did. if($num_haros<0) { for($i =0; $i > $num_haros; $i--){ if($i <= 0 && $i > -5) { echo "<img src=\"/images/haropink.png\" alt=\"\" />"; } elseif($i >= -10 && $i < -5) { echo "<img src=\"/images/haro1pink.PNG\" alt=\"\" />"; } } } else { for($i =0; $i <= $num_haros; $i++){ if($i < 10 && $i >= 5){ echo "<img src=\"/images/harolgreen.PNG\" alt=\"\" />"; }elseif ($i < 5 && $i >= 0){ echo "<img src=\"/images/harogreen.png\" alt=\"\" />"; } } } I had to use the if statement and then change the fors for -- and >=$num_haros Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410772 Share on other sites More sharing options...
BillyBoB Posted December 10, 2007 Share Posted December 10, 2007 No problem Glad to be of some help. Quote Link to comment https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/#findComment-410778 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.