caran
Posts: 15
|
Posted: 11/30/2011, 8:42 AM |
|
Hy, i´m a absolute newby and my english is not very well. hope you understand my problem.
I`m using CCS 4.3 / PHP / postgreSQL
I want have a checkbox in an editable grid. If i click on the checkbox i want to write directly the value to the database.
Is it correct when i`m using the "onClick"-Event? How must the customcode looks like?
i`ll tried like this:
if ($fakturakopf->fkk_bezahlt->GetValue() == 1) {
$belegnr = $fakturakopf->fkk_belegnr->GetValue();
$ccs_result22 = $DBWLPG01->query("update fakturakopf set fkk_bezahlt = 1 where fkk_belegnr = $belegnr");
}
|
|
|
djgjohn
Posts: 52
|
Posted: 12/01/2011, 12:53 AM |
|
This post is very good:
http://forums.codecharge.com/posts.php?post_id=60507
Following should give you a clue:
PHP
global $form_name;
for ($j = 1; $j <= $form_name->PageSize + $form_name->EmptyRows; $j++)
if (strlen(CCGetParam("field_name_" . $j, ""))!=0 )
echo "Field value in row " . $j. " is " . CCGetParam("field_name_" . $j, "")."<br>";
else
echo "Field value in row ". $j." is empty<br>";
Basically you need to loop through the rows submitted and execute your query. Create a new connection object for each loop.
So (this is a guide) -
global $belegnr;
for ($j = 1; $j <= $form_name->PageSize + $form_name->EmptyRows; $j++) {
if (strlen(CCGetParam("fkk_bezahlt_" . $j, "")) == 1) {
// Create new connection (whatever your connection is)
$DB = new clsDBConnection1();
$SQL = "update fakturakopf set fkk_bezahlt = 1 where fkk_belegnr = '".$belegnr."'";
$result = $DB->query($SQL);
if (!$result) {
echo "Query: ".$SQL.$j."<BR>";
echo "Query failed: ".mysql_error()."<BR>";
}
// Close connection
unset($DB);
}
}
Try onclick server-side event.
|
|
|
caran
Posts: 15
|
Posted: 12/01/2011, 2:59 AM |
|
Thank you for your quick reply!
There some Questions open from me:
1.) Did i understand right, that the event not started by clicking on the checkbox and so that the event should be started by clicking on a (submit-)button?
(The onClick Server side event i only found by creating a Button)
2) I change "$DB = new clsDBConnection1();" to "$DB = new clsDBWLPG01();"
Think thats right?
3) Must i change "$form_name" too? (into "$FakturaBearbeiten" )
I´ll tried this so, but it doesnt work.
|
|
|
datadoit
|
Posted: 12/01/2011, 5:45 AM |
|
If you want to trigger the database update upon client-side clicking on
the checkbox, then you'll have to use AJAX.
Yes, it will be the checkbox's client-side OnClick event.
I'll leave it open-ended like this so that you can determine if AJAX is
something you want to delve into, or simply stick with a server-side
update (Submit button).
|
|
|
caran
Posts: 15
|
Posted: 12/01/2011, 8:14 AM |
|
Thanks for your answer, too!
I think in this moment AJAX is too complex for me. i`d like to understand the similar things first.
i tried in different ways, but till now it doesnt work
So i think i didnt see something important.
The Name of my Page is FakturaBearbeiten
It holds a editableGrid called fakturakopf
in this grid i made a checkbox with toolbox-->forms the ControlSource is fkk_bezahlt
now i made in the bottomline of the grid a Button1 - the type is submit
Properties-Events-Server-onclick-add code
At the Code-Page i fill in this Code:
global $belegnr;
for ($j = 1; $j <= $form_name->PageSize + $form_name->EmptyRows; $j++) {
if (strlen(CCGetParam("fkk_bezahlt_" . $j, "")) == 1) {
$DB = new clsDBWLPG01();
$SQL = "update fakturakopf set fkk_bezahlt = 1 where fkk_belegnr = '".$belegnr."'";
$result = $DB->query($SQL);
if (!$result) {
echo "Query: ".$SQL.$j."<BR>";
echo "Query failed: ".mysql_error()."<BR>"; //i use pg
}
unset($DB);
}
}
-->live page
-->start browser, open the page, click on the checkbox, click on button1, the hook disappears no other echos are seen.
|
|
|
datadoit
|
Posted: 12/01/2011, 9:30 AM |
|
Not necessary to have any custom coding. Place your checkbox control on
your editable grid as you have done. Bind it to your database field.
The button will be an Update button. Nothing else to do.
|
|
|
djgjohn
Posts: 52
|
Posted: 12/01/2011, 2:24 PM |
|
Looks like row update is conditional on checkbox being selected. If this is true then this code should work. I am surprised you never got a PHP error calling PageSize on a non-object.
Using the code I supplied, you need to change:
for ($j = 1; $j <= $form_name->PageSize + $form_name->EmptyRows; $j++) {
to:
for ($j = 1; $j <= $fakturakopf->PageSize + $fakturakopf->EmptyRows; $j++) {
(Sorry, should have mentioned this. Please try again and come back.)
|
|
|
djgjohn
Posts: 52
|
Posted: 12/01/2011, 3:44 PM |
|
Forgot to answer these questions:
1.) Did i understand right, that the event not started by clicking on the checkbox and so that the event should be started by clicking on a (submit-)button?
(The onClick Server side event i only found by creating a Button)
Yes. As I understand it you only want to update the rows where the checkbox is checked. So you check the boxes, then click submit button. If you use the editable grid builder, a submit button is automatically generated. If you continue having trouble, you might have to re-create the editable grid using the builder to make a clean start.
2) I change "$DB = new clsDBConnection1();" to "$DB = new clsDBWLPG01();"
Think thats right?
Yes. However, from experience I know that keeping connection names as general as possible is a good idea mainly so you can duplicate projects for other purposes and be able to reuse connection names. Irrelevant connection names can be confusing and annoying.
|
|
|
datadoit
|
Posted: 12/01/2011, 5:24 PM |
|
On 12/1/2011 6:44 PM, djgjohn wrote:
> 2) I change "$DB = new clsDBConnection1();" to "$DB = new clsDBWLPG01();"
> Think thats right?
>
> Yes. However, from experience I know that keeping connection names as general
> as possible is a good idea mainly so you can duplicate projects for other
> purposes and be able to reuse connection names. Irrelevant connection names can
> be confusing and annoying.
Excellent advice.
|
|
|
caran
Posts: 15
|
Posted: 12/02/2011, 12:01 AM |
|
Thank You Guys!
I am on a RoadTrip now, but i will check it out at the weekend.
I hope, i can report success on monday
|
|
|
djgjohn
Posts: 52
|
Posted: 12/02/2011, 3:27 PM |
|
Call me obsessive but... Did he receive no error when called $form_name->PageSize because PageSize is not a method (function) it is a property?
|
|
|
caran
Posts: 15
|
Posted: 12/14/2011, 9:54 AM |
|
No, he didnt receive any error.
Now i build the Grid complet new and now it works
|
|
|