Print Page | Close Window

Mod Req : Show 5 Random Topic ...

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Forums Modifications
Forum Description: Mod's and Add-on's for Web Wiz Forums.
URL: https://forums.webwiz.net/forum_posts.asp?TID=20422
Printed Date: 30 March 2026 at 12:09pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Mod Req : Show 5 Random Topic ...
Posted By: miladanimator
Subject: Mod Req : Show 5 Random Topic ...
Date Posted: 25 June 2006 at 1:32pm
I need a mod to show 5 (x) random topic in default.asp file ...

any one have a code to show random datas from database ?



Replies:
Posted By: chicken
Date Posted: 06 July 2006 at 12:49pm
i would like this awell


Posted By: chicken
Date Posted: 21 December 2006 at 12:13pm
anyone?


Posted By: MrMellie
Date Posted: 21 December 2006 at 1:19pm
I've got top 8 random picture selections on my Photo Album mod, I'll go and check the code (been 2 years since I done it), the same principle should work.


Posted By: chicken
Date Posted: 21 December 2006 at 1:41pm
thanks :)


Posted By: MrMellie
Date Posted: 21 December 2006 at 2:21pm
Ok, this is lifted straight out of my MOD, so you'll need to adapt it to read the topic ID's from the topics table etc.

     strSQL="SELECT MAX(IMAGEID) AS MAXID FROM PA_IMAGES" 

     rs.Open strSQL, dbCon, adOpenStatic ,adLockReadOnly
     nMax = rs("maxid")
     rs.Close
     nMin = 1
     rs.Open "SELECT IMAGEID FROM PA_IMAGES", dbCon,adOpenStatic

     RndCnt=1
     do while RndCnt < 9
          Randomize     
          nRnd = Int((nMax - nMin + 1)*Rnd() + nMin)
          rs.MoveFirst
          rs.Find("IMAGEID=")&nRnd
          if rs.EOF = false then
               if instr(strRand,cstr(nRnd))=0 then
                    strRand=strRand & cstr(nRnd) & ","
                    RndCnt=RndCnt+1
               end if
          end if
     loop
     strRand=left(strRand,len(strRand)-1)
     rs.Close

     rs.Open "SELECT I.IMAGEID,I.IMAGE,I.APPROVED,M_NAME FROM PA_IMAGES I,PA_USERS U WHERE I.MEMBER_ID=U.MEMBER_ID AND I.IMAGEID IN(" &strRand &")", dbCon, adOpenStatic ,adLockReadOnly
          
So, what's happening is, you first get the maximum value of ID in the table, then loop though 8 times (change this to 5 for your mod) and generate a random integer between 1 and this max ID. This gets concatenated into a string that is then used in the last query to fetch the ID's from the Topic table that are in the list stored in the string. Hope that makes sense!!


Posted By: chicken
Date Posted: 22 December 2006 at 6:32pm
ok cool thanks i will try and see what i can do



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net