CodeCharge Studio
search Register Login  

Web Reports

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 Not display records on first page load with no Search criteria set

Print topic Send  topic

Author Message

Posts: 35
Posted: 09/10/2015, 9:25 AM

Hi all,
This has probably been answered before but I am buggered if I can locate anything.

Can someone please tell me how I stop the "search" from getting all records on a given
page when it loads? I want an empty grid until search criteria are set.

View profile  Send private message

Posts: 513
Posted: 09/10/2015, 8:54 PM


I usually set the 'Hide/Show' of the results grid unless there is a parameter from the Search so you don't get anything until you have a Search term ('keyword' in this example)

Eg: GridResults > Before Show > Add Action > Hide/Show
Set GridResults to 'Hide' if Parameter 1 URL value 'keyword' equals '' (Parameter 2 Expression)

You could also do something in the Before Select to check for sometime similar (CCGetFromGet('keyword','') and cancel the Select (I think you can return a 'false' from the Before Select - not sure though)


CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
View profile  Send private message

Posts: 37
Posted: 09/14/2015, 10:33 AM

I do exactly the same thing as eratech, and I use this on a lot of pages where you never want to see a bunch of records mixed together. For example, I force the user to select a Scenario in the search box. If they don't the grid is not displayed, but I do show a large red message telling them they must first select a Scenario.

Instead of an action as eratech shows, I use the Grid / Before Show to check a parameter and then make it visible or not:
    // Do not allow the user to see the grid if a Scenario has not been chosen.  
	if (CCGetParam("s_ScenarioID",-1) == -1 OR CCGetParam("s_ScenarioID") == NULL)  
		$Component->Visible = False;  
		$Component->Visible = True;  

I do the same thing with the red warning label, but of course the true and false conditions are backwards.

However, since this is not a very secure way to restrict the data--someone can mess with the URL--I also carry around a ClientID session variable that is part of the data selection process. So if a client tries to access another client's scenario, the result will be blank. If a client wants to guess at what their own Scenario ID's are, then fine, no harm done. So this sort of combines forcing the user to choose a Scenario first, with reasonable security in the background.

View profile  Send private message

Posts: 638
Posted: 09/14/2015, 3:26 PM

Using the visual query builder "Table Paramter" in the select WHERE statements for the primary key of the table you are searching on, example UserID = UserID, Session - for the 'Use Default Value if parameter is empty use 0 (zero)'

You can do the same with the search field criteria

for example firstname = s_firstname, URL, 'Use Default Value if parameter is empty use 0 (zero)'
Central Coast, NSW, Australia.

View profile  Send private message

Posts: 37
Posted: 09/14/2015, 6:30 PM

MM, I had a little trouble following your post, but I think you're saying that instead of suppressing the grid itself when the user has not chosen a critical value, that you use the ability of visual query builder to throw a zero in the WHERE clause and therefore get no match at all on the data! That's very clever, and actually better than my approach, although not displaying the grid at all and displaying a large red message is pretty dramatic, you have to admit! :-)

I think one thing you have to be careful with, which again I'm reading into your post, is that the default is to simply ignore any missing parameters, and we don't want that, we want them specifically used to force no matches on the data. Ignoring missing criteria is what caused the problem in the first place and resulted in tons of inappropriate data.

So, unless I distorted what you were saying, great idea MM!
View profile  Send private message

Posts: 35
Posted: 09/14/2015, 6:49 PM

Thank you MM that was exactly the answer I needed.
Appreciate your effort.
Essentially I have a UserId that must be set to only allow
the user to see records relevant to them.
This now stops any records being displayed until such
time as the user enters specific criteria and we set the user id.

thanks again.
View profile  Send private message

Posts: 191
Posted: 09/14/2015, 10:45 PM

I use the ASP.Net InMotion templates but there might be some crossover here. Seems like I read somewhere that if the grid isn't visible, it doesn't execute the select. So in the before select event I checked the query string parameters and if they are all blank or null, I set the grid's Visible property to false.

View profile  Send private message

Posts: 638
Posted: 09/14/2015, 11:35 PM

Further to my explanation if one field exists with default parameter 0, unless a value is given in a search field or from a session variable for that, the entire search fails. So you then have to start looking at combinations of that and IS NULL and possibly passing matching search sets through parentheses (brackets :) )
Central Coast, NSW, Australia.

View profile  Send private message

Posts: 35
Posted: 09/15/2015, 4:52 AM

Thank you for all the replies. I appreciate your time and effort.
I finally have the solution to my issue...
The resulting solution is entirely based on Michaels response.

Thanks again.
View profile  Send private message
Posted: 09/15/2015, 11:11 AM

If you're feeling adventurous, and want to harness some of the power of
CodeCharge objects and controls ...

When you have a search form with fields, clicking 'Search' with no field
values will produce this in your URL:

etc. Quite ugly. So clean up that URL to omit values that are NULL by
adding a Server -> On Validate event to your search record form. Choose
Choose Add Action and Declare Variable.

Name: _POST
Initial Value: array_diff(array_unique($_POST),array(""))

What that will do is clear all NULL URL parameters. Now think about how
you could use that in the results grid for more logical control of what
is shown and what is not shown.

In your particular situation, maybe you don't want to show the results
grid at all if no search criteria is given. So, in your Before Show
event for the grid choose Add Action and Hide-Show Component.

Component Name: Choose your grid object
Action: Hide
Condition Type: Expression
Condition: CCStrLen(CCGetQueryString("QueryString", "")) < 1

Now this is overkill for what you asked for, as MM has given the easiest
way from point A to point B. But for full granularity, such as maybe
just hiding header and footer rows from the results grid, or just hiding
certain columns from the grid based on what was searched for, etc., then
try the above.

Posts: 191
Posted: 09/16/2015, 5:26 PM


Do you know how this could be done in the ASP.Net InMotion templates? I got tired of recreating the same search parameters over and over in my reports and grids so I created an includable page that contains a search form with all possible parameters. I created some properties on the includable page so I can control which parameters to show for each report. The problem is that every parameter gets put into the query string, even the hidden ones. I'd love to get rid of those when they are blank.

View profile  Send private message
Posted: 09/17/2015, 1:31 PM

Sorry I do not. I'll be happy to convert your ASP.Net OldMotion
Template program to PHP Templates for a nominal fee. :)

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

PHP Reports

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

Home   |    Search   |    Members   |    Register   |    Login

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