Jump to content

Is it possible? PHP/CSS


liamloveslearning

Recommended Posts

Hi everyone,

 

I want to have 3 divs on my page which change according to the data in my table.

I want 3 rows, Div 1, Div 2 and div 3, in my table div 1 will have a value of 40, div 2 a value of 10 and div 3 a value of 60.

 

Is it possible to have a php calculation which adds all the totals togethor, and then work out what percentage of that sum is and output the calculation as the width of each div?

 

So for example DIV 1 would be whatever % 40 is of 110?

 

Sorry if this is confusing!

Link to comment
https://forums.phpfreaks.com/topic/200049-is-it-possible-phpcss/
Share on other sites

Perhaps...

 

$val1 = 40;
$val2 = 10;
$val3 = 60;
$all = $val1 + $val2 + $val3;
$pval1 = floor(($val1 / $all) * 100);
$pval2 = floor(($val2 / $all) * 100);
$pval3 = 100 - ($pval1 + $pval2);
?>
<div id="1" style="position:relative;height:100%;width:<?PHP echo $pval1; ?>%;background-color:teal;float:left;padding:0;"><? echo $val1; ?></div> 
<div id="2" style="position:relative;height:100%;width:<?PHP echo $pval2; ?>%;background-color:teal;float:left;padding:0;"><? echo $val2; ?></div> 
<div id="3" style="position:relative;height:100%;width:<?PHP echo $pval3; ?>%;background-color:teal;float:left;padding:0;"><? echo $val3; ?></div> 
<?PHP

 

make sense?

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.