dzulishak
Posts: 12
|
Posted: 12/19/2012, 6:26 PM |
|
Hello,
can some one help me using if else statement in codecharge using php?
i want to add if else statement to check if $ bakiasal < jum_tolak ( error message : Baki tidak mencukupi) then if the $bakiasal is greater then jum_tolak then the system wil do the deduction. can someone help me?
--before insert--
$tarif2=CCGetFromGet(id_tarif);
$bakiasal=CCGetFromGet(baki_kuantiti);
$jumtolak= $tolak->jum_keluar->GetValue();
//penolakan
$jumbaru = $bakiasal - $jumtolak;
$tolak->Label3->SetValue($jumbaru);
//update row table tarif
$db= new clsDBkuantiti;
$sql="UPDATE tarif SET baki_kuantiti =$jumbaru WHERE id_tarif=". $tarif2;
$db->query($sql);
$db->close;
|
|
|
saseow
Posts: 744
|
Posted: 12/19/2012, 8:01 PM |
|
It works something like this:
--before insert--
$tarif2=CCGetFromGet(id_tarif);
$bakiasal=CCGetFromGet(baki_kuantiti);
$jumtolak= $tolak->jum_keluar->GetValue();
//here is the check
if ($bakiasal < $jumtolak)
{
$Container->Errors->addError("Bakiasal is smaller than Jumtoluk!");
}
else
{
//penolakan
$jumbaru = $bakiasal - $jumtolak;
$tolak->Label3->SetValue($jumbaru);
//update row table tarif
$db= new clsDBkuantiti;
$sql="UPDATE tarif SET baki_kuantiti =$jumbaru WHERE id_tarif=". $tarif2;
$db->query($sql);
$db->close;
}
|
|
|
dzulishak
Posts: 12
|
Posted: 12/19/2012, 8:54 PM |
|
Quote saseow:
It works something like this:
--before insert--
$tarif2=CCGetFromGet(id_tarif);
$bakiasal=CCGetFromGet(baki_kuantiti);
$jumtolak= $tolak->jum_keluar->GetValue();
//here is the check
if ($bakiasal < $jumtolak)
{
$Container->Errors->addError("Bakiasal is smaller than Jumtoluk!");
}
else
{
//penolakan
$jumbaru = $bakiasal - $jumtolak;
$tolak->Label3->SetValue($jumbaru);
//update row table tarif
$db= new clsDBkuantiti;
$sql="UPDATE tarif SET baki_kuantiti =$jumbaru WHERE id_tarif=". $tarif2;
$db->query($sql);
$db->close;
}
thanks saseow it's work
|
|
|
dzulishak
Posts: 12
|
Posted: 12/19/2012, 11:31 PM |
|
1 question...how to prevent data to record?
|
|
|
saseow
Posts: 744
|
Posted: 12/20/2012, 2:36 AM |
|
The $Container->Errors will stop the data from being inserted.
Search the help file for InsertAllowed to see how to do it without adding custom error messages.
e.g.
$items->InsertAllowed = false;
|
|
|
dzulishak
Posts: 12
|
Posted: 12/20/2012, 5:12 PM |
|
ok.thanks sesow for advice..will try it..
|
|
|
dzulishak
Posts: 12
|
Posted: 12/27/2012, 12:13 AM |
|
i just got 1 question:
i have 2 database db A and db B if iuse if else statement :
if ($bakiasal < $jumtolak)
{
$Container->Errors->addError("Bakiasal is smaller than Jumtoluk!");
}
else
{
//penolakan (DATABASE B)
$jumbaru = $bakiasal - $jumtolak;
$tolak->Label3->SetValue($jumbaru);
//update row table tarif
$db= new clsDBkuantiti;
$sql="UPDATE tarif SET baki_kuantiti =$jumbaru WHERE id_tarif=". $tarif2;
$db->query($sql);
$db->close;
what should i do to prevent database A from save data if ($bakiasal < $jumtolak) ?
anyone can help me?
|
|
|
Lucius
Posts: 220
|
Posted: 01/09/2013, 6:49 AM |
|
I don't know if you are looking exactly for this, but check CCS help (F1 in designer) and search this topic: InsertAllowed Run-Time Property (PHP)
|
|
|