syedasimmeesaq: Tell us what you're trying to do - I can't figure out your objective from the code here. Depending on the objectives of the script, you might be able to use multi-dimensional arrays. Thanks, ~Ray

I'm sure we can condense the code by using functions, variable references ("$$" variables) and /or multidimensional arrays or objects. But as we said, explain more about your goals - we don't need to see the code, just want to get an idea of the 100 inputs and expected outputs. Thanks, ~Ray

yes I am trying to get a count of how many 1s, 2s, 3s and 0s are in a field. Then I after I get those below in the formula I am doing some calculations.
After I know how many 1s in B1 for example, I hold that in $B1_arr[1], so if there are five 1s in B1 field , $B1_arr[1] is 5. If there are three 0's in there, I will have $B1_arr[0] = 3

You would not insert it into your current code...you would replace your current code (up to about line 100 in your post) with this system. At line 100, instead of going through each individual variable, you would go through the 1st-level elements of the $tally_arr array.

<?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)...

It still seems like we can find a more generalized example that is easy for you to adapt. Can you please post your query and show us the structure of the tables? Thanks, ~Ray

heilo what about the part after I execute the while loop? Also in your above suggestion it was B. Should it not be $B as we are trying to set the value of variable $B to zero.

@ray

here is the query

$alltable = mysql_query("select * from Table where District_ID='".$_SESSION['user']."' ") or die ("union err: ".mysql_error());

$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

<?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) . " %"; }}

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose.
It turns out that Yahoâ€¦

This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.