PDA

View Full Version : Repeat Region - Need to do calculation


alamask
04-23-2007, 06:14 PM
ok, here is an ex how the table should be
+--------+---------+----------+
+__start_+_End____+_Result___+
+--------+---------+----------+
+ 3 ____ + 5______ + 2______ +
+--------+---------+----------+

"start" and "end" are dynamic data from recordset, result = End - Start.
so how do I calculate and display the "Result" in the Repeat Region?

P.S to be more specific, calculation is in Time, which is a piece of crap

davidj
04-23-2007, 06:40 PM
just perform the calculation as normal using your data variables


datavar['field1'] - datavar['field1'];

alamask
04-23-2007, 07:46 PM
welll you cant really do calculation on it, since dynamic data is in string format, and calculation need to be done in Time, so i have to convert data in to time format then do calculation but this won't work in the repeat region.
i know this can be done by doing calculation on the Recordset, but just havent figured out how to do that yet haha.

davidj
04-23-2007, 08:24 PM
post your code

alamask
04-25-2007, 08:03 PM
I solved the time calculation part, i did that inside the query so i can display it in the repeat region also.
Now I encounter a more complicated issue.
I have to do arithmetic calculation with the recordset that I created. Lets say i chose all the records from a database with a certain characteristic..the results are put in the recordset and display on the page. BUt lets say i need to find: MIN(), MAX(), AVG()....from these records. then how should i go about this? i dont see any function in ASP that does these arithmetic operations

davidj
04-25-2007, 08:06 PM
so your wanting to perform calcs on the dynamic table and on the row values yes?

alamask
04-25-2007, 08:35 PM
yeah! thats it haha

davidj
04-25-2007, 09:18 PM
i can write this and explain in php

dont know it would be of any help to you

alamask
04-25-2007, 09:24 PM
well im using asp so..maybe if you just describe the general idea. like how do i pull out data from the recordset and do calculation ..or something

davidj
04-25-2007, 09:36 PM
ok

in PHP in the LOOP i can do this...


do{ //<< this is the begining of the loop

$variable = $variable + $row['db_field'];//<< $row['db_field'] is what is used to display db data


}

// after the loop finishes i can echo or print the result

echo $variable;


i can also count how many times it loops...


$count = 0;
do{ //<< this is the begining of the loop

$variable = $variable + $row['db_field']; //<< will add row columns and $variable will contain the total

$count++;//<< increment $count variable
}

echo $count; //<< displays the total line count


so to get the average you could...


$count = 0;
do{ //<< this is the begining of the loop

$variable = $variable + $row['db_field']; //<< will add row columns and $variable will contain the total

$count++;
}

echo $variable / $count; //<< displays the average;