CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Counting records

Print topic Send  topic

Author Message
mavtech

Posts: 133
Posted: 09/27/2004, 1:52 PM

I have a grid. With Courses listed on it. when I click on a course I can then see the students listed in another grid on the same page.

I would like to count the number of students in each course and have it displayed in the main grid.
Example:
Course_Name// Course_Date// Number_of_students

So it must count the number of students with the course_name = Course_name

Can somone help.

Paul
View profile  Send private message
lvalverdeb

Posts: 299
Posted: 09/27/2004, 3:22 PM

Assuming that you have three tables e.g. courses, students and coursesbystudent (which has a course_id and a student_id fields), I would suggest you try this in the beforeshowrow event:
<code>
global $coursesgrid;
$db = new clsDByourconnection();
$StudentCount = CCDLookUp("count(*)","coursesbystudent","course_id=".$coursesgrid->ds->f("course_id"),$db);
$coursesgrid->number_of_students->SetValue(strval($StudentCount));
unset($db);

</code>

Luis
_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4
View profile  Send private message
mavtech

Posts: 133
Posted: 09/28/2004, 6:22 AM

There actually is only one table(not my design).

When the table has a RECTYPE = 'P' it is the course name.
When the table has a RECTYPE = 'PC" it is the student name
Both lines will have the same OPID.

Paul
View profile  Send private message
peterr


Posts: 5971
Posted: 09/28/2004, 6:36 AM

Just use an SQL query that groups and counts the number of students. If you base a grid on such a query (data source) then it will work automatically and you don't need to do any calculations or lookups in CCS itself.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
mavtech

Posts: 133
Posted: 09/28/2004, 7:53 AM

Please explain in more detail how to do this ??:-)
View profile  Send private message
peterr


Posts: 5971
Posted: 09/28/2004, 8:27 AM

This would probably require teaching the SQL, which is not something that I can do here. Though I can recommend to you some online tutorials on the SQL COUNT function:
http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=sql+count
http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=sql+tutorial+count
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
mavtech

Posts: 133
Posted: 09/28/2004, 11:04 AM

Whenever I create a label field and set"
Control Source Type to Database Expression and Set
Control Source to something like SELECT COUNT("OPID") FROM "Opmgr" I alway get an syntax error.

What am I doing wrong.
View profile  Send private message
peterr


Posts: 5971
Posted: 09/29/2004, 1:41 AM

A SELECT statement is a SQL statement, not an expression. An expression may be COUNT("OPID") but I'm not sure if this will or should work. You should just use the full SQL statement in the datasource of your form (instead of a Table), then simply select the calculated field as the control source of your label.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message

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.