Dorin
Posts: 50
|
| Posted: 10/25/2010, 11:12 PM |
|
Hello,
I have a mysql table (amounts), that looks like:
date | amount | type
-------------------------------
date1 | x | 1
date2 | y | 2
date3 | z | 1
.....
In a page, that could have or not a url parameter for date (data_s), I want to have a label that will show a total calculated like this:
if (!CCGetFromGet("data_s","")) then {
global $DBConnection1;
$Page = CCGetParentPage($sender);
$ccs_result = CCDLookUp("sum(amount)", "amounts", "type=1" and "date <=CURDATE()") - CCDLookUp("sum(amount)", "amounts", "type=2" and "date <=CURDATE()")
$Page->Connections["DBConnection1"]);
$Container->Label1->SetValue($ccs_result);
}
else
{
global $DBConnection1;
$Page = CCGetParentPage($sender);
$ccs_result = CCDLookUp("sum(amount)", "amounts", "type=1" and "date <=CCGetFromGet("data_s","")") - CCDLookUp("sum(amount)", "amounts", "type=2" and "date <=CCGetFromGet("data_s","")")
$Page->Connections["DBConnection1"]);
$Container->Label1->SetValue($ccs_result);
}
But my code it's a mess. Could anyone help me?
Many thanks
|
 |
 |
Dorin
Posts: 50
|
| Posted: 10/26/2010, 5:36 AM |
|
ok, I found some mistakes so the code now looks like:
$global $DBConnection1;
$Page = CCGetParentPage($sender);
if (CCGetParam("data_","")=="") {
$ccs_result = CCDLookUp("sum(amount)", "amounts", "iTip=1 and data<=CURDATE()", $Page->Connections["Connection1"]) - CCDLookUp("sum(amount)", "amounts", "iTip=2 and data<=CURDATE()", $Page->Connections["Connection1"]);
}
else {
$ccs_result = CCDLookUp("sum(amount)", "amounts", "iTip=1 and data<=".CCGetParam("data_s",""), $Page->Connections["Connection1"]) - CCDLookUp("sum(suma)", "registru", "iTip=2 and data<=".CCGetParam("data_s",""), $Page->Connections["Connection1"]);
}
$Container->Label1->SetValue($ccs_result);
The code works only when there is no url parameter (data_s). If I have the data_s parameter, the result is invariable 0.
|
 |
 |
Dorin
Posts: 50
|
| Posted: 10/27/2010, 2:06 AM |
|
after some of my nails got eaten, i figure out:
global $DBConnection1;
$Page = CCGetParentPage($sender);
if (CCGetParam("data_s","")=="") {
$ccs_result = CCDLookUp("sum(amount)", "amounts", "iTip=1 and data <= CURDATE()", $Page->Connections["Connection1"]) - CCDLookUp("sum(amount)", "amounts", "iTip=2 and data <= CURDATE()", $Page->Connections["Connection1"]);
}
else {
$datax=CCGetParam("data_s","");
$ccs_result = CCDLookUp("sum(amount)", "amounts", "iTip=1 and data <='".$datax."'", $Page->Connections["Connection1"]) - CCDLookUp("sum(amount)", "amounts", "iTip=2 and data <='".$datax."'", $Page->Connections["Connection1"]);
}
$Container->Label1->SetValue($ccs_result);
|
 |
 |
|