Random content daily? Can It be done?

Results 1 to 3 of 3

Thread: Random content daily? Can It be done?

  1. #1
    Join Date
    Dec 1969

    Default Random content daily? Can It be done?

    I would like content pulled from a database on a daily basis? So every day it would pick a random row out of a database table and plug it into a page. I have seen ASP & SQL randomly pull content out of a database, but it changes every time the page loads, can it be done so it only changes once a day?

  2. #2
    Join Date
    Dec 1969

    Default RE: Random content daily? Can It be done?

    Here is an idea that might work.<BR><BR>Create a application variable called currentDate and set it to today.<BR><BR>When you open your page compare the value of Application("CurrentDate") with Date<BR><BR>If Application("CurrentDate") &#060;&#062; Date() then<BR> change the value of your random row generator<BR> change the value of the Application("CurrentDate") to Date()<BR>End If<BR><BR>Your SQL statement would pull records based on the value of your random variable<BR><BR>This should change the value of the random variable the first time a page is called each day, and then open up the same row each time after that.<BR><BR>Hope this helps<BR><BR>Dennis<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Random content daily? Not too hard

    Dennis&#039 answer is almost there, but I feel that you could help your performance by pulling the row from the DB at the same time you change the date.<BR><BR>And if you do all this in Session_onStart in your GLOBAL.ASA file, then you know it will always get done.<BR><BR>Finally, be sure to use an Application.Lock/Unlock sequence around the date change!<BR><BR>Something like this, then, in the GLOBAL.ASA file:<BR><BR>Sub Application_onStart<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#0 39 choose a date in the past so first session <BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 will always trigger the get-new-message code!<BR>&nbsp;&nbsp;&nbsp;&nbsp;Application("Curr entDate") = CDate("1/1/1999")<BR>End Sub<BR><BR>Sub Session_onStart<BR>&nbsp;&nbsp;&nbsp;&nbsp;Applica tion.Lock<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 get out fast if still same date...<BR>&nbsp;&nbsp;&nbsp;&nbsp;If Date = Application("CurrentDate") Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;Application.Unlock<BR>&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub<BR>&nbsp;&nbsp;&nbsp;&nbsp;End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 if here, need a new msg from DB<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 but first change the app&#039s date:<BR>&nbsp;&nbsp;&nbsp;&nbsp;Application("Curr entDate") = Date<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 now, open the DB, pull out a random record ...<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#039 and assign the record value to another App value:<BR>&nbsp;&nbsp;&nbsp;&nbsp;Application("Cur rentMessage") = RS("messageFromTable")<BR>&nbsp;&nbsp;&nbsp;&nbsp; &#039 then close the RS and the connection<BR>End Sub<BR><BR>**************<BR><BR>How do you choose a random record? Lots of ways: Easiest is to simply number your records and choose a random number somewhere in the range of record numbers. You might want to remember the last few randomly chosen numbers (in another Application value) so that you don&#039t choose same one too close.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts