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.
|
 |
 |
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.
|
 |
 |
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.... :)
|
 |
 |
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.
|
|
|
 |
|