Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use <cfflush> to display a large database on a page

Status
Not open for further replies.

bnymk

Programmer
Feb 7, 2003
296
US
Hi All:

I have a query that returns a large number of data at a time, sometimes up to 4000 records. I know I could make the query to return 50 records at a time but that's not what the customer wants at this time and wants to see all the records at one time on a single page. I've heard of cfflush but don't know how I can be able to use it on my query to display whatever record it gets immdeately on a page so the waiting period will be short before waiting for all 4000 records.

Thanks

"Behind every great fortune there lies a great crime", Honore De Balzac
 
Live docs has a good example of how to use it.


make the loops run longer to see how it work better.

You'll want a higher number than 10. the first <cfflush> tag will send the headers and any html you want (probably all of it before your output loop) the next tag has an interval set it to a few hundred probably. be sure it is outside of your loop.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
You should explain to the customer how load-heavy this is... and if the data is not critical... which I'm not sure that it is because noone reads through 4000 records repeatedly... can you cache the results?

We all go through this, our bosses ask for us to do something, it is then up to us to do it and consider the implications of doing it. And once considering those implications (load weight for instance) its up to us whether to say something or not... of course don't push too hard because ... no job then.

I've had bosses that wanted every opinion I had, they couldn't get enough of my thoughts on things, and I've had bosses that didn't want to hear a thing about it... I like the ones in between the most... The first seem sort of patronizing.. the latter are rude.. But in between you'll find people who do think they're smarter than everyone else but know there's a reason they hired you.

But that's all kind of off topic... Bombboy is right on cfflush.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
The key is to not be offended or frustrated when/if you suggest a better method but they don't want it. It's their data, if they want it a certian way, let them have it. You just may have to explain the expected limitations of the systems proformance. For every give there is take.
make a car faster, gas milage goes down. same thing here.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Thanks, I will look into that

"Behind every great fortune there lies a great crime", Honore De Balzac
 
ok...I tried implementing <cfflush> and am not getting what I want. The page is not loading any faster that it used before and am not noticing any change. What I was hoping to achieve by using <cfflush> was the return the data right away in chunks so users can see at leat the beginning of the data and build it slowly thereafter. Here is the code that I'm using and please someone take a look at it and let me know what I'm doing wrong.

Thanks.

<cfoutput>
<script language="JavaScript">
<!--
nonCounterProcessingWindow();
//-->
</script>
</cfoutput>

<cfloop from="0" to="100" step="25" index="i">
<cfquery datasource="#request.dsn#" name="Query1" cachedwithin="#CreateTimeSpan(1,0,0,0)#">
SELECT DISTINCT table1.columnName1,table1.columnName2,table2.colmnName3, table2.columnName4
FROM table1, table2
WHERE table1.columnName1 = table2.column_id
ORDER BY columnName2
</cfquery>
<cfset PercentDone = PercentDone + 25>
<cfif PercentDone EQ 100>
<cfset Confirmation="Currently building the dynamic tree to be displayed in the left-hand pane.">
</cfif>
<!--- A javscript routine to display/replace the progress page with counter and text message --->
<cfoutput>
<script language="JavaScript">
<!--
counterProcessingWindow("#variables.PercentDone#", "#variables.Confirmation#");
//-->
</script>
</cfoutput>
</cfloop>

and then I build the table like this.
<table width="100%" border="1" bgcolor="#808AAD">
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
<th>header4</th>
</tr>
<cfflush>
<cfloop qyery="Query1">
<tr>
<td>#table1.columnName1#</td>
<td>#table1.columnName2#</td>
<td>#table2.columnName3#</td>
<td>#table2.columnName4#</td>
</tr>
</table>


"Behind every great fortune there lies a great crime", Honore De Balzac
 
Code:
</tr>
<cfflush>
<cfloop qyery="Query1">
<tr>

should be
Code:
</tr>
<cfflush>
<cfflush interval=200><!--- or other number --->
<cfloop qyery="Query1">
<tr>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
I tried using the interval attribute but it didn't make any difference. The page gets loaded after all the records are fetched. My understanding of a cfflush was that it will dump whatever record that it gets onto a browser and continue populating the data up to the last record afterwards, so the users will get to see some data right away before waiting for all the records.

"Behind every great fortune there lies a great crime", Honore De Balzac
 
Try changing

Code:
</tr>
<cfflush>
<cfloop qyery="Query1">
<tr>

to this

Code:
</tr>
<cfloop qyery="Query1">
<cfif [i]Query1.[b][u]AutoNumberID[/u][/b][/i] mod [red]10[/red] eq 0>
<cfflush></cfif>
<tr>

You must change the emphasized line to the correct Primary Key ID name...

You can change the red 10 to any other number.

I will say that (on cf5, anyway) I've had pages where cfflush refused to do anything, and then other pages where it was great to go.. better than 1400 times (it flushed an id to a textbox to let me know what ID this script was freezing at).


ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
I have tried everyone's suggestion posted on this forum but there doesn't seem to be any change at all. It still displays the data all at once and not in chunks as I hoped so the load will be faster. Any other ideas????

"Behind every great fortune there lies a great crime", Honore De Balzac
 
According to the CF Help files:
The first occurrence of this tag on a page sends back the HTML headers and any other available HTML. Subsequent cfflush tags on the page send only the output that was generated after the previous flush.

When you flush data, ensure that enough information is available, as some browsers might not respond if you flush only a small amount. Similarly, set the interval attribute for a few hundred bytes or more, but not thousands of bytes.

Use the interval attribute only when a large amount of output will be sent to the client, such as in a cfloop or a cfoutput of a large query...
Maybe you should try a cfflush just before you run your query, then have another one (with an interval) just before your output loop.

This may not be any help, I've only used cfflush once.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Hey bombboy, I didn't realize you'd already posted a link to the Live docs article. Oops.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Not a problem Ecobb. it's monday.

I've tried something similar and it doesn't work for me either. I've tried 200, 400, 800, and 1000. After that didn't work I tried real small too 10, 20. It worked on there example but not in a query output.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Ok, I put <cfflush> right before the query execution and right after but still no change.

<cfflush>
<cfloop from="0" to="100" step="25" index="i">
<cfquery datasource="#request.dsn#" name="Query1" cachedwithin="#CreateTimeSpan(1,0,0,0)#">
SELECT DISTINCT table1.columnName1,table1.columnName2,table2.colmnName3, table2.columnName4
FROM table1, table2
WHERE table1.columnName1 = table2.column_id
ORDER BY columnName2
</cfquery>
<cfset PercentDone = PercentDone + 25>
<cfif PercentDone EQ 100>
<cfset Confirmation="Currently building the dynamic tree to be displayed in the left-hand pane.">
</cfif>
<!--- A javscript routine to display/replace the progress page with counter and text message --->
<cfoutput>
<script language="JavaScript">
<!--
counterProcessingWindow("#variables.PercentDone#", "#variables.Confirmation#");
//-->
</script>
</cfoutput>
<cfflush>
</cfloop>

and then I build the table like this.
<table width="100%" border="1" bgcolor="#808AAD">
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
<th>header4</th>
</tr>
<cfflush interval="200">
<cfloop qyery="Query1">
<tr>
<td>#table1.columnName1#</td>
<td>#table1.columnName2#</td>
<td>#table2.columnName3#</td>
<td>#table2.columnName4#</td>
</tr>
</table>

I don't know why its not working. It's becoming a frustrating experience.



"Behind every great fortune there lies a great crime", Honore De Balzac
 
Hi bynymk,

I'm no expert on CFFLUSH. I've only used it occasionally, so I may be wrong here.

I think the problem in your code is that you are running two CFLOOPS and expecting them both to flush at the same time. There's no reason for the code to move on to the second CFLOOP (the one that displays data) until the first loop is over.

I would try to make the code work more like this:

<table width="100%" border="1" bgcolor="#808AAD">
<tr>
<th>header1</th>
<th>header2</th>
<th>header3</th>
<th>header4</th>
</tr>
<cfloop from="0" to="100" step="25" index="i">
<cfquery datasource="#request.dsn#" name="ThisQuery" cachedwithin="#CreateTimeSpan(1,0,0,0)#">
    SELECT         DISTINCT table1.columnName1,table1.columnName2,table2.colmnName3, table2.columnName4
    FROM             table1, table2
    WHERE         table1.columnName1 = table2.column_id
    ORDER BY     columnName2
</cfquery>
<cfset PercentDone = PercentDone + 25>
<cfif PercentDone EQ 100>
    <cfset Confirmation="Currently building the dynamic tree to be displayed in the left-hand pane.">
</cfif>
<!--- A javscript routine to display/replace the progress page with counter and text message --->
<cfoutput>
    <script language="JavaScript">
    <!--
        counterProcessingWindow("#variables.PercentDone#", "#variables.Confirmation#");
    //-->
    </script>
<cfloop query="thisquery">
<tr>
<td>#table1.columnName1#</td>
<td>#table1.columnName2#</td>
<td>#table2.columnName3#</td>
<td>#table2.columnName4#</td>
</tr>
</cfloop>
</cfoutput>
<cfflush>
</cfloop>
</table>

If that doesn't work, try taking the content out of the 'table' tag. The fact that the table isn't closed until after the entire loop is over probably isn't helping your case. I think most browsers won't show any of a table's contents until they have a closing tag.

I may be wrong though. Hope it helps you figure it out : )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top