liamloveslearning Posted April 28, 2010 Share Posted April 28, 2010 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 More sharing options...
Ken2k7 Posted April 28, 2010 Share Posted April 28, 2010 Yes, it's possible. For what it's worth, you don't even need PHP. You can do that with JavaScript. Link to comment https://forums.phpfreaks.com/topic/200049-is-it-possible-phpcss/#findComment-1049973 Share on other sites More sharing options...
litebearer Posted April 28, 2010 Share Posted April 28, 2010 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? Link to comment https://forums.phpfreaks.com/topic/200049-is-it-possible-phpcss/#findComment-1050020 Share on other sites More sharing options...
Ken2k7 Posted April 28, 2010 Share Posted April 28, 2010 Okay... that's one way. Are the vars static? Link to comment https://forums.phpfreaks.com/topic/200049-is-it-possible-phpcss/#findComment-1050023 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.