CodeCharge Studio
search Register Login  

Visual Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 [Resolved] Checkbox in Grid

Print topic Send  topic

Author Message
m1l

Posts: 4
Posted: 07/03/2008, 11:26 AM

I have a grid of records, which I would like the user to pick which ones they will use at the next step, so when they have checked all records they want, when they press a button, it then inserts those into another table and move on to that step.

I have found one EXTREMELY nasty way of doing this and that is to create a grid that allows record deletion, then edit the PHP (not _events.php, the php!!!) file to not delete records but do certain things in its place.

This is nasty, horrible and more importantly, dangerous, as if you regenerate you are highly likely to lose what you've done and put all the deletion stuff back in it's place.

Does anyone have an idea of how to do this a proper way?
View profile  Send private message
datadoit
Posted: 07/03/2008, 12:32 PM

I don't believe there is a wrong way or right way of doing things
programatically when it works. So, here's a 'suggested' way...

Your editable grid has Allow Update set to Yes, and for your
Button_Update OnClick event:

<code>
# chkAction is the name of your checkbox.

foreach ($Container->FormParameters['chkAction'] as $key=>$value) {
if ($value != "") {
$Field1 = $Container->CachedColumns['Field1'][$key];
$Field2 = $Container->CachedColumns['Field2'][$key];
etc.
$ConnectionDB->query("INSERT INTO YourTable SET Field1=$Field1,
Field2=$Field2");
}
}

# When done, send them to the next page.
header("Location: NextPage.php"); exit;
</code>

Now this example is very generic and doesn't include things like data
validation, proper SQL, etc., but you should get the idea.

Here's an excellent source of information on getting values from an
editable grid:

http://forums.codecharge.com/posts.php?post_id=60507
mentecky

Posts: 321
Posted: 07/03/2008, 12:36 PM

Quote m1l:
I have a grid of records, which I would like the user to pick which ones they will use at the next step, so when they have checked all records they want, when they press a button, it then inserts those into another table and move on to that step.

I have found one EXTREMELY nasty way of doing this and that is to create a grid that allows record deletion, then edit the PHP (not _events.php, the php!!!) file to not delete records but do certain things in its place.

This is nasty, horrible and more importantly, dangerous, as if you regenerate you are highly likely to lose what you've done and put all the deletion stuff back in it's place.

Does anyone have an idea of how to do this a proper way?

Well, this is still kind of ugly but will work, I believe. Use an editable grid like you describe and allow "Delete" to create the checkboxes and code for processing them. Then click the grid and select the "Custom Delete" property. Change the TYPE field to SQL. Edit the SQL to do an INSERT into the other table rather than the DELETE.

That's it. It should work fine and will survive regeneration and CCS upgrades.

Rick
_________________
http://www.ccselite.com
View profile  Send private message
m1l

Posts: 4
Posted: 07/03/2008, 12:51 PM

Rick,

This sounds interesting and would work perfect for the insert. There is a header table but I think I can probably do something in the before show on the page, put the id of the newly created record into a session variable and use that in the insert. I will try this and if it works I will mark the post as fixed.

Thanks and thanks to datadoit for the reply, appreciated.
View profile  Send private message
m1l

Posts: 4
Posted: 07/04/2008, 5:32 AM

I tried Ricks way and it works like a dream.

In before show on the page I have

$db = new clsDBConnection1();
$SQL = "insert into searches (type) values (1)";
$db->query($SQL);
$new_id = mysql_insert_id();
$db->close();
session_register("search_id");
$_SESSION["search_id"] = $new_id;

Then on the record I have a custom delete of

insert into search_results (search_id, survey_id) values ('".$_SESSION['search_id'];"', {id})

and on the return page of the editable grid I set to the page of the next part of the process.
View profile  Send private message
mentecky

Posts: 321
Posted: 07/04/2008, 1:40 PM

m1l,

Glad we could help!

Rick
_________________
http://www.ccselite.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.

PHP Reports

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

Home   |    Search   |    Members   |    Register   |    Login


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