A Better Way

Results 1 to 2 of 2

Thread: A Better Way

  1. #1
    Join Date
    Dec 1969

    Default A Better Way

    I was trying to figure out to randomize a record set and found that it might be better for me to choose a different solution.<BR>The idea is to display a number of records on a page that will change everytime the page is loaded. <BR>Instead of creating a random record set to display I wrote a the following.<BR>Is there a better way to solve this problem. I am calling the database a lot and think that it might be better for me to do an update on all the records I display instead of each one at a time.<BR><BR>&#039;FIND MAX # VIEWS<BR>strSQL = "SELECT Max(fldViews) AS fldMaxViews "<BR>strSQL = strSQL & "FROM tblRandomRec;"<BR><BR>Set rsRec = connList.Execute(strSQL)<BR><BR>intMax = rsRec("fldMaxViews")<BR><BR>&#039; SET NUMBER OF RECORDS TO DISPLAY<BR>intCount = 5<BR><BR>&#039; INITIALIZE COUNTER<BR>intTotalCounter = 0<BR><BR>Do Until intTotalCounter &#062;= intCount<BR> <BR> Call SelectList(intCount, intMax)<BR> <BR> Do Until rsRec.EOF OR intTotalCounter &#062;= intCount<BR> <BR> intTotalCounter = intTotalCounter + 1<BR> &#039;Response.Write "Total Number: &#060;b&#062;" & intTotalCounter & "&#060;/b&#062;&#060;/br&#062;" <BR> Response.Write rsRec("fldStatement") & "<BR>"<BR> Call UpdateDB(rsRec("fldID"),rsRec("fldViews"))<BR> rsRec.MoveNext<BR> <BR> Loop<BR> <BR> intMax = intMax + 1<BR> <BR>Loop<BR><BR>MTmace

  2. #2
    Join Date
    Dec 1969

    Default Sure, easy...

    Use the same WHERE clause in the UPDATE that you do in the SELECT.<BR><BR>So:<BR><BR> SQLupdate = "UPDATE tablename SET fldViews=fldViews+1 " _<BR> & " WHERE fldID IN (" & listOfFIeldIdsFromSelect & ")"<BR><BR>Since you don&#039;t show the code for your SUBs, I can&#039;t guess beyond that. Personally, I would *use* SUBs for this, since it&#039;s specialized enough that it deserves custom coding. But that&#039;s your choice.<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