This topic is locked

Totals on vertical layout

12/15/2006 12:24:19 PM
PHPRunner General questions
S
siegfried.hansen author

Okay, looks like I am a real pain in the butt today; I hope noone get pissed <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=4215&image=1&table=forumtopics' class='bbc_emoticon' alt=':unsure:' />
By reading the help I understood that the totals aren't permitted on the vertical layout.
But wouldn't be possible to get a total of the records by adding a new table called, let's say "grand_total" and use the 'after record added' event 'insert a record into another table' to get the number from the added record in order to UPDATE the "grand_total" value?
<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=4215&image=2&table=forumtopics' class='bbc_emoticon' alt=':blink:' /> Whoa...what the heck did I just say?
Let's try to make it more clear: after adding a record in a main table, it's total goes to the "grand_total" table where that total is added to the existing one so the field is updating and show the actual values.
Cheers!
Sieg

J
Jane 12/19/2006

Sieg,
sure you can do it using Before record added event.

Here is a sample code:

function BeforeAdd(&$values)

{

global $conn;
$strSQLInsert = "insert into grand_total (TotalField) values (".$values["FieldName"].")";

db_exec($strSQLInsert,$conn);
$str = "select sum(TotalField) from grand_total";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

echo $data[0];
return true;

}



where TotalField is your actual field name in the grand_total table, FieldName is your actual field name in the main table.