$allrows = mysql_num_rows($alltable);
//as we are only interested in 1 and 2 which are yes and No respectively, we just set 1 and 2 of every column to count //from zer0
$i=0;
$B1_arr[1]=0;
$B1_arr[2]=0;
$B2_arr[1]=0;
$B2_arr[2]=0;
$B5_arr[1]=0;
$B5_arr[2]=0;
$B17_arr[1]=0;
$B17_arr[2]=0;
$B19_arr[1]=0;
$B19_arr[2]=0;
$B22_arr[1]=0;
$B22_arr[2]=0;
$C6_arr[1]=0;
$C6_arr[2]=0;
$C9_arr[1]=0;
$C9_arr[2]=0;
while ($i < $allrows)
{
$B1 = mysql_result($alltable, $i, "B1");
$B2 = mysql_result($alltable, $i, "B2");
$B5 = mysql_result($alltable, $i, "B5");
$B17 = mysql_result($alltable, $i, "B17");
$B19 = mysql_result($alltable, $i, "B19");
$B22 = mysql_result($alltable, $i, "B22");
$C6 = mysql_result($alltable, $i, "C6");
$C9 = mysql_result($alltable, $i, "C9");
if($B1==1){
$B1_arr[$B1]++;
}
if($B1==3){
$B1t_arr[$B1]++;
}
if($B1==0){
$B1N_arr[$B1]++;
}
if($B2==1){
$B2_arr[$B2]++;
}
if($B2==3){
$B2t_arr[$B2]++;
}
if($B5==1){
$B5_arr[$B5]++;
}
if($B5==3){
$B5t_arr[$B5]++;
}
if($B17==1){
$B17_arr[$B17]++;
}
if($B17==3){
$B17t_arr[$B17]++;
}
if($B19==1){
$B19_arr[$B19]++;
}
if($B19==3){
$B19t_arr[$B19]++;
}
if($B22==1){
$B22_arr[$B22]++;
}
if($B22==3){
$B22t_arr[$B22]++;
}
if($C6==1){
$C6_arr[$C6]++;
}
if($C6==3){
$C6t_arr[$C6]++;
}
if($C9==1){
$C9_arr[$C9]++;
}
if($C9==3){
$C9t_arr[$C9]++;
}
$i++;
}
//echo "</table><br>";
$B1trows = $allrows - $B1t_arr[3];
$B1pre = ($B1_arr[1] / $B1trows) * 100;
$B1 = number_format($B1pre, 2)." %";
$B2trows = $allrows - $B2t_arr[3];
$B2pre = ($B2_arr[1] / $B2trows) * 100;
$B2 = number_format($B2pre, 2)." %";
$B5trows = $allrows - $B5t_arr[3];
$B5pre = ($B5_arr[1] / $B5trows) * 100;
$B5 = number_format($B5pre, 2)." %";
$B17trows = $allrows - $B17t_arr[3];
$B17pre = ($B17_arr[1] / $B17trows) * 100;
$B17 = number_format($B17pre, 2)." %";
$B19trows = $allrows - $B19t_arr[3];
$B19pre = ($B19_arr[1] / $B19trows) * 100;
$B19 = number_format($B19pre, 2)." %";
$B22trows = $allrows - $B22t_arr[3];
$B22pre = ($B22_arr[1] / $B22trows) * 100;
$B22 = number_format($B22pre, 2)." %";
$C6trows = $allrows - $C6t_arr[3];
$C6pre = ($C6_arr[1] / $C6trows) * 100;
$C6 = number_format($C6pre, 2)." %";
$C9trows = $allrows - $C9t_arr[3];
$C9pre = ($C9_arr[1] / $C9trows) * 100;
$C9 = number_format($C9pre, 2)." %";
<?
$tally_arr = array();
while ($row=mysql_fetch_assoc($result)) {
foreach ($field_arr as $val) {
$tally_arr[$val][$row[$val]]++;
}
}
?>
<?php
$allrows = mysql_num_rows($alltable);
//as we are only interested in 1 and 2 which are yes and No respectively, we just set 1 and 2 of every column to count //from zer0
$i=0;
$temp=array('B'=>'1,2,5,17,19,22', 'C'=>'6,9');
foreach($temp as $k => $v)
{
$temp2=explode(",",$v);
foreach($temp2 as $v2)
{
${$k.$v2.'_arr'}=0;
}
}
while ($i < $allrows)
...
<?php
$allrows = mysql_num_rows($alltable);
//as we are only interested in 1 and 2 which are yes and No respectively, we just set 1 and 2 of every column to count //from zer0
$temp=array('B'=>'1,2,5,17,19,22', 'C'=>'6,9');
foreach($temp as $k => $v)
{
$temp2=explode(",",$v);
foreach($temp2 as $v2)
{
${$k.$v2.'_arr'}=0;
}
}
while($data=mysql_fetch_assoc($alltable))
{
foreach($data as $k=>$v){
if( $k=='B1' && (int)$v==0)
{
$B1N_arr[$B1]++;
}
elseif( (int)$v==1 )
{
${$k.'_arr'}[$k]++;
}
elseif( (int)$v==3 )
{
${$k.'t_arr'}[$k]++;
}
}
}
foreach($temp as $k => $v)
{
$temp2=explode(",",$v);
foreach($temp2 as $v2)
{
${$k.$v2.'trows'}=$allrows - ${$k.$v2.'t_arr'}[3];
${$k.$v2.'pre'}=(${$k.$v2.'_arr'}[1] / ${$k.$v2.'trows'})*100;
${$k.$v2}=number_format(${$k.$v2.'pre'}, 2) . " %";
}
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
15 Experts available now in Live!