CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Insert record only where checkbox = 1

Print topic Send  topic

Author Message
jerryvernon

Posts: 35
Posted: 05/12/2004, 1:57 PM

I have the following code which inserts an the contents of an editable grid record into another table called shortlist.

Works OK

I would like only to insert the record into the shortlist table where checkbox1 = 1.

What script do I add to the script below in order to allow this to happen

function Update()
{
$this->BlockExecution = true;
$this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeBuildInsert");
//$this->WHERE $bs_items1->CheckBox1->GetValue = "1";
$this->SQL = "INSERT INTO shortlist ("
. "user_id, "
. "actor_id, "
. "image_url, "
. "name, "
. "notes"
. ") VALUES ("
. $this->ToSQL($this->user_id->GetDBValue(), $this->user_id->DataType) . ", "
. $this->ToSQL($this->item_id->GetDBValue(), $this->item_id->DataType) . ", "
. $this->ToSQL($this->image_url->GetDBValue(), $this->image_url->DataType) . ", "
. $this->ToSQL($this->name->GetDBValue(), $this->name->DataType) . ", "
. $this->ToSQL($this->notes->GetDBValue(), $this->notes->DataType)
. ") WHERE ("
. "CheckBox1 = 1"
. ")" ;
$this->CCSEventResult = CCGetEvent($this->CCSEvents, "BeforeExecuteInsert");
if($this->Errors->Count() == 0 && $this->BlockExecution) {
$this->query($this->SQL);
$this->CCSEventResult = CCGetEvent($this->CCSEvents, "AfterExecuteInsert");
}
$this->close();
}
View profile  Send private message
peterr


Posts: 5971
Posted: 05/12/2004, 3:29 PM

I noticed that your code sample looks exactly like the PHP code generated by CCS, therefore I'm not sure if you modified the generated code, or copied it into an event?
I strongly recommend that you do not modify the script generated by CCS unless absolutely necessary. Such modifications can make your program incompatible with future versions of CCS. Your program may also stop working correctly when you modify your form in the Design mode after making such changes.
The generated code almost never needs to be modified.

If you placed your code within an event (for example "After Execute Update") then you probably don't need the Where statement, just do not execute your Insert code at all if the value of the checkbox is different than 1. You can use the GetValue method for this ( http://docs.codecharge.com/studio/html/Components/Methods/PHP/GetValue.html ), for example:
if ($GridName->CheckboxName->GetValue() == 1) {...execute your INSERT SQL here...}
_________________
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.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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