Jump to content

[SOLVED] Set number of images?


L

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/80959-solved-set-number-of-images/
Share on other sites

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?

$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.

 

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.

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

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.