I'm coding a PHP progress bar that will update itself via a percent number that is given to it but I'm having issues working out the percents.
My code currently is as follows:
PHP
$percent = $_GET['percent'];
if($percent < 5)
//low-image.jpg
elseif($percent > 95)
//high-image.jpg
else{
$lowpercent = 100 - $percent;
$highwidth = 270 / 100 * $percent;
$lowwidth = 270 / 100 * $lowpercent;
HTML
<div class="first"></div>
<div class="mid-first" style="width:<?=$highwidth?>px;"></div>
<div class="mid-second" style="width:<?=$lowwidth?>px;"></div>
<div class="last"></div>
CSS
.first. mid-first, .mid-second, .last{
display:block;
float:left;
height:62px;
}
.first{
background:url(low.png);
width:31px;
}
.mid-first{
background:url(mid-first.png) repeat-x;
}
.mid-second{
background:url(mid-second.png);
}
.last{
background:url(high.png);
width:32px;
}
The Problem
At the moment the percents are worked out slightly incorrectly, my maths brain seems to have been misplaced today...
There are 4 divs, the first and last div take up 5% each so 10%, the middle divs then equal the other 90%.
This means when the figure 50 is given passed in via the $_GET
it will work out 50% of the middle bars not including the 5% first bar, which is wrong, it should take the first 5% into account and then work out the 50% pixel widths?
How can I change the maths behind the percent to fix the two middle bars so that when 50% is applied both middle bars are equal in pixels?