CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Calculate the SUM of a Field

Print topic Send  topic

Author Message
DataDoIt
Posted: 01/12/2004, 10:03 PM

CCS2; PHP4; MySQL4

Howdy, I'm attempting to get the SUM of a column of integers. Here's what
I've done:

1. Created a page using the Record and Grid Builder with a Search Form.

2. In the search results section, just below where it displays the Total
Records Found number, I inserted a new Label and call it {TotalStudents}.
This value I want calculated from a field in the table called
{NumberStudents}. I want it to calculate ONLY the number of students from
the search results, just like the Total Records Found number is from the
search results.

3. In the label's Before Show Event, I insert Custom Code that I swiped
from the CCS Knowledge Base:

global $DB<connection_name>;
if ($<form_name>->ds->Where == "")
[$<form_name>->]<label_name>->SetValue(CCDLookUp("count(*)",
"<table_name>", "0=0", $DB<connection_name>));
else
[$<form_name>->]<label_name>->SetValue(CCDLookUp("count(*)",
"<table_name>", $<form_name>->ds->Where, $DB<connection_name>));

Okay, so now here's where I'm lost. :-)

4. I'm attempting to display this TotalStudents value NOT on a form, thus
there is no <form_name>. What do I use here?

5. The <connection_name> is straightforward I think. The <table_name> is
straightforward I think. Would I replace "count(*)" with
"sum(<NumberStudents>)" ?

6. Am I even close???

Thanks!

-Mike R.

bb
Posted: 01/12/2004, 8:51 PM

//DLookup @95-6DD122D4
global $DBMIS;
global $Deposit_Header;
$result = CCDLookUp("SUM(amount)", "Deposit_Detail", "deposit_index=".$Deposit_Header->deposit->GetValue(), $DBMIS);
$result = doubleval($result);
$Deposit_Header->batch_total->SetValue($result);
//End DLookup
TAiNT

Posts:
Posted: 01/13/2004, 6:25 AM

As variant
In BeforeShowRow event you can summarize all integers in some global variable

// Before Show Row
global $FromName // this generated by CCS (you doesn't mentioned how your form named in the project)
global $total; // added by you

$total =+$FromName->NumberStudents->GetValue();
// End Before Show Row

After it in Before show Event of TotalStudents label :

// Before Show
global $TotalStudents // this generated by CCS (may be something else depending on where exactly you placed this Label)
global $total; // added by you

$TotalStudents->SetValue($total);
// End Before Show
View profile  Send private message
DataDoIt
Posted: 01/13/2004, 12:05 PM

"TAiNT" <TAiNT@forum.codecharge> wrote in message
news:54003ffe903650@news.codecharge.com...
> As variant
> In BeforeShowRow event you can summarize all integers in some global
variable
>
> // Before Show Row
> global $FromName // this generated by CCS (you doesn't mentioned how
your form named in the project)

> global $total; // added by you
>
> $total =+$FromName->NumberStudents->GetValue();
> // End Before Show Row
>
> After it in Before show Event of TotalStudents label :
>
> // Before Show
> global $TotalStudents // this generated by CCS (may be something else
depending on where exactly you placed this Label)

> global $total; // added by you
>
> $TotalStudents->SetValue($total);
> // End Before Show
> _________________
> Take care...
> ---------------------------------------

Hi, thanks for the tip. However, I'm still a little confused as to "where"
to place this code. Please bear with me...

The place where I want to display my new TotalStudents value is not on a
form. I created this page using the Record and Grid builder, with a search
form. The place where I want to display the TotalStudents is below the
Search form, above the results grid, which is above the change/edit form. I
"think" I have two forms, and one results grid on this page: Search form,
results from the search grid, and a change/edit form. Please correct me if
I'm wrong.

Thus, I created the label TotalStudents and placed it between the Search
Form and the Results Grid. Then, in the Results Grid Before Show Row
section, I inserted your code above, which looks like:

--------------------------------------------------
//waiting_list_BeforeShowRow @2-EB30740D
function waiting_list_BeforeShowRow()
{
$waiting_list_BeforeShowRow = true;
//End waiting_list_BeforeShowRow

//Custom Code @85-6706C035
// -------------------------
global $waiting_list;
global $total;
$total=+$waiting_list->NumberScholarshipChildren->GetValue();
// Write your own code here.
// -------------------------
//End Custom Code

//Close waiting_list_BeforeShowRow @2-ECA1931B
return $waiting_list_BeforeShowRow;
}
//End Close waiting_list_BeforeShowRow
----------------------------------------------

Then, I went to the Label TotalStudents, and inserted Custom Code for Before
Show:

----------------------------------------------
//waiting_list_TotalStudents_BeforeShow @83-25B9FA68
function waiting_list_TotalStudents_BeforeShow()
{
$waiting_list_TotalStudents_BeforeShow = true;
//End waiting_list_TotalStudents_BeforeShow

//Custom Code @84-6706C035
// -------------------------
global $TotalStudents;
global $total;
$TotalStudents->SetValue($total);
// Write your own code here.
// -------------------------
//End Custom Code

//Close waiting_list_TotalStudents_BeforeShow @83-17980448
return $waiting_list_TotalStudents_BeforeShow;
}
//End Close waiting_list_TotalStudents_BeforeShow
----------------------------------------------

Given all that, I'm getting an error that says "Call to a member function on
a non-object". Where did I screw up?

Thanks!

-Mike R.




Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.