CodeCharge Studio
search Register Login  

Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Calculate Grid value from feelds and db

Print topic Send  topic

Author Message
NeverHood


Posts: 4
Posted: 05/22/2010, 7:21 AM

Hello
i have
1). grid :
----------------------------------------------------------------------------
| rezerv_id | rezerv_name | rezerv_date | rezerv_balance |
-----------------------------------------------------------------------------

2). Mysql table REZERV with field :
rezerv_id , rezerv_name ,rezerv_date , rezerv_sw1, rezerv_sw2, rezerv_sw3, ..........,rezerv_sw50

rezerv_sw(X) have - 0 or 1 value

how to calculate the grid "rezerv_balance" , if rezerv_balance = rezerv_sw1 +rezerv_sw2 + rezerv_sw3+ ................rezerv_sw49+rezerv_sw50 ?

thanks in advance
Excuse me for my english.
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 05/22/2010, 9:30 PM

NeverHood,
You are definitely heading in the right direction. You can create a column as a part of the data source (as a part of the MySQL query) for the grid that adds the columns up for you.
View profile  Send private message
damian

Posts: 838
Posted: 05/23/2010, 3:17 AM

you would do something like this in your sql statement...

SELECT rezerv_id , rezerv_name ,rezerv_date , rezerv_sw1, rezerv_sw2, rezerv_sw3, ..........,rezerv_sw50, rezerv_sw1 +rezerv_sw2 + rezerv_sw3+ ................rezerv_sw49+rezerv_sw50 as rezerv_balance
from ...
where ...

using SQL as your datasource....

you can then add a label and set the source as rezerv_balance....


_________________
if you found this post useful take the time to help someone else.... :)
View profile  Send private message
datadoit
Posted: 05/23/2010, 5:55 AM

To avoid having to write longwinded queries and/or PHP calculations on
all fifty of those fields, may want to consider normalizing your data
structure a little more by creating a separate table for those reserv_sw
values, then joining them with your primary table when appropriate.

Something like:

rezerv_sw_id (AUTOINCREMENT)
rezerv_id
rezerv_sw

Your unique primary key will be the fields rezerv_sw_id and rezerv_id.
Your joins will be on rezerv_id, and you'll simply SUM the values from
rezerv_sw needed. Something like:

SELECT REZERV.rezerv_id, rezerv_name, rezerv_date,
SUM(REZERV_SUB.rezerv_sw) AS rezerv_balance FROM REZERV LEFT JOIN
REZERV_SUB ON (REZERV.rezerv_id = REZERV_SUB.rezerv_id) GROUP BY
REZERV_SUB.rezerv_id

This will also allow you to have unlimited rezerv_sw values, not just 50.

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.

PHP Reports

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

Home   |    Search   |    Members   |    Register   |    Login


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