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!!