keep what you got with the 24 hour cache... add your tipUsed column to the table

when u have a tip to display.. throw an update query in there to flag the tipUsed column as used

thats pretty much it :)

so now when the cache expires, the next tip will be grabbed and flagged

<cfquery name="gettip" datasource="MYDSN" maxrows="1" cachedwithin"#CreateTimeSpan(1,0,0,0)#">
select * from tbl_tips where tipUsed = 0
</cfquery>

this will grab the first tip that it comes to where TipUsed is 0

now set the tip being used as Used

<!--- If there was no record returned then the table is either empty or all tips are set to USED and will need to be reset --->
<cfif GetTip.RecordCount is 0>
    <!--- Reset all tips to NOT USED --->
    <cfquery name="ResetTips" datasource="MYDSN">
    UPDATE tbl_Tips
    SET TipUsed = 0
    </cfquery>

    <!--- after its reset, THEN grab your tip and cache it --->
    <cfquery name="gettip" datasource="MYDSN" maxrows="1" cachedwithin"#CreateTimeSpan(1,0,0,0)#">
    select * from tbl_tips where tipUsed = 0
    </cfquery>

</cfif>

<!--- now as long as your table is not empty, you have a tip and can set it to USED (TipUsed = 0) --->
<cfif GetTip.RecordCount NEQ 0>
    <cfquery name="UpdateTip" datasource="MYDSN">
        UPDATE tbl_Tips
        SET TipUsed = 1
        WHERE TipID = #val(GetTip.TipID)#
    </cfquery>

    <cfoutput>#GetTip.Tip#</cfoutput>
</cfif>
  ----- Original Message -----
  From: daniel kessler
  To: CF-Talk
  Sent: Wednesday, August 11, 2004 2:02 PM
  Subject: Re: tip of the day

  ok, I have another TOTD question.  I was told that each tip can only be displayed once and that they would prefer that I go down the list from record 1 to n.  When all records are displayed once, then I can go through the list again.

  I have a thought on a way to do this, but not sure if it's sensible or the best way:

  1 - Have a "tip_used" column.
  2 - Query for a list of unused tips, sorted by their ID field will will be an ascending unique number.
  3 - If the number of unused tips is 0, then go through all the records and set them all to unused  ( ? )
  3 - Grab the first tip, get it's ID.
  4 - Query for that ID and make it a cached query.

  and maybe i can put all this in a <cflock> to make it all happen at once?

  All thoughts are appreciated.

  > http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/appfra29.htm
  >
  > it will cache it for everyone, its a server side cache
   
  > ----- Original Message -----
   
  > From: daniel kessler
   
  > To: CF-Talk
   
  > Sent: Wednesday, August 04, 2004 3:59 PM
   
  > Subject: Re: tip of the day
  >
  >
   
  > So by caching the query, it assures that everyone gets the same random
  > TIP for the day or just that particular machine?
  >
   
  > > well there are a couple of ways to get a random record...
   
  > > as long as ou are not using access there is a RAND() function to do
  > it...
   
  > >
   
  > > something like this if i remember correctly
   
  > >
   
  > > select * from table order by Rand() limit 1
   
  > >
   
  > > that SHOULD return 1 random record everytime its ran.
   
  > >
   
  > > you could also get all of the IDs from the table and then select a
   
  > > radom ID from the #ValueList(QueryName.QueryColumn)# variable
   
  > >
   
  > > like...
   
  > > <cfquery name="IDs" datasource="datasource">
   
  > > select ID from table
   
  > > </cfquery>
   
  > >
   
  > > <cfset randomID = listGetAt(valuelist(IDs.ID), RandRange(1,
   
  > > listlen(Valuelist(IDs.ID)))>
   
  > >
   
  > > then just select * from table where ID = #val(randomid)#
   
  > >
   
  > >
   
  > > the caching part is easy, it is an attribute of the cfquery tag and
  > as
   
  > > long as its not cleared or the server rebooted, or CF services
   
  > > restarted, then it should last the full cached duration...
   
  > >
   
  > > for 24 hours...
   
  > >
   
  > > <cfquery name="QueryName" datasource="datasourcename"
   
  > > cachedwithin="#createtimespan(0,24,0,0)#">
   
  > > select whatever
   
  > > </cfquery>
   
  > >
   
  > >
   
  > > ** CreateTimeSpan(Days,Hours,Minutes,Seconds)
   
  > >
   
  > >
   
  > >
      
  >
   
  > > ----- Original Message -----
      
  >
   
  > > From: daniel kessler
      
  >
   
  > > To: CF-Talk
      
  >
   
  > > Sent: Tuesday, August 03, 2004 1:36 PM
      
  >
   
  > > Subject: Re: tip of the day
   
  > >
   
  > >
      
  >
   
  > > > Id stick with ID and tip, pull a random one each time and cache
  > the
   
  > >
      
  >
   
  > > > query for 24 hours.
   
  > >
      
  >
   
  > > That brings up some questions.  So, I pull a random tip each day,
  > not
   
  > > a random tip each page refresh.  So what pulls the random tip and
  > sets
   
  > > it as the TOTD?  I've also not yet looked into caching queries.  
  > ugh
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to