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

 Dynamic Data Source Adjustment (Using checkboxes, dropdowns, etc.)

Print topic Send  topic

Author Message
cdolson

Posts: 27
Posted: 05/29/2008, 9:56 AM

I am trying to set up some kind of a function whereby there would be a checkbox that, when checked, would pass on a custom parameter into the data source.

Something like: [box checked] = WHERE total > 0

But if the box is not checked, nothing is passed into the data source parameters.

What would be the function for creating dynamically adjustable query parameters?

Thank you for your help.
View profile  Send private message
wkempees


Posts: 1679
Posted: 05/29/2008, 11:49 AM

[Help File: Examples and Techniques, Programming, Dynamically Modifying........]

PHP:
BeforeBuildSelect Event, add Custom Code
Check if Checkbox checked and then alter the WHERE clause.

Also be aware to test the $Component->ds->Where.
If it has a value, ovverride it or add to it or store it so you can reset it, and so on
  
if ( $Component.checkboxfieldname->GetValue() ==$Component.checkboxfieldname->CheckedValue() )  
   $Component->ds->Where = 'some condition=some value';  

Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
View profile  Send private message
cdolson

Posts: 27
Posted: 05/29/2008, 1:17 PM

Thank you for your reply Walter.

I have found the help topic you mentioned, but I am unable to see how I should link the custom code to a checkbox. You say to: "check if Checkbox checked and the alter the WHERE clause." How do I make this happen?

I see how I should insert code into the Before Build Select event - but how do I cause this to trigger based on a checkbox?

Thank you very much for your help!

Chris

View profile  Send private message
wkempees


Posts: 1679
Posted: 05/29/2008, 3:44 PM

Chris
There are always several challenges and/or solutions, just no problems.

First things First:
Suppose a Search + Grid combo.
The Search has one or several search fields on it, and a submit ('Search') button.
All that this does is POST the data entered in the search field and call the Grid.

The Grid goes through several events (i.e. Initialize, BeforeShow, BeforeBuildSelect) and eventualy it executes it's (! own) SQL and goes through several other event (BeforeShowRow....) and shows the selected data rows on your grid.
That SQL you have either reached through setting parameters in the Grid Builder or entered by hand using VisualQueryBuilder.
The SQL is composed of the SELECT-FROM, the WHERE and the ORDER, constructs.
If you have a standard Grid with Search build through the Builder the WHERE will be composed for you, and mainly creates FIELD comparison POSTEDFIELD.

Two major thing are important here:
1, the values fed to the where clause are taken from the posted search fields.
2, the Where (and the Order) are composed as separate parameters internally and can be changed (by you) in the BeforeBuildSelect.

So, in BeforeBuildSelect, you can 'see'the content of the WHERE itself, without being bothered by all the other SQL, same goes for the ORDER.
The next thin g that happens after this event is that CCS builds a full SQL statement using the 3 parts and opotimizing them, sometimes even adding some more code (LIMIT...) after it.

All in ALL CCS hands you a convenient way of altering the WHERE statement.

Go to the BeforBuildSelect event of the Grid.
Experiment with altering the WHERE, by just typing a (supposed) valid condition like
$Component->ds->Where = "total >0";
I am assuming here, your grid has no Where set, if you want to avaoid that burdon you just test for any content first, and then decide if you want to ADD to the Where or REPLACE it.
  
if ( $Component->ds->Where=="") {     // empty  
    
} else {       // not empty  
  
}  

  
  
$Component->ds->Where = "total >0";   // will replace the Where  
$Component->ds->Where .= " AND total >0";   // will add to the existing the Where  
  
Next you want to get te value of the field in your search form, assume s_checkbox is the field.
CCGetParam("s_checkbox,"") will do that

Now take it from here......or tempt me to go even further (...)

Walter
@MB: Video subject here!
[P=1100]
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)

if you liked this info PAYPAL me: http://donate.consultair.eu
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.