Hi all,

I've tried and tried, and tried again to solve this one on my own with no
success.  I'm sure it's pretty ez, but since i'm a "coder" and not a
"programmer" this is just beyond my abilities i think.

Designing a shopping page that should randomly pull up to 5 records
(stores).  The random number generated should NOT be a duplicate of it self
at any time through the loop...  That last part is the part I can't seem to
do...

Sigh.

Here's the code i've got right now (try not to laugh):

<CFSET temp = ValueList(getStores.pkStoreID)>
<CFSET tempnum = #ListLen(temp)#>
<CFOUTPUT>
<table border="0" align="center" width="100%">
  <cfset NewNum = 0>
  <cfloop query="getStores" startrow="1" endrow="5">
    <CFSET randtemp = #RandRange(1,tempnum)#>
    <CFSET #RANDNUMBER# = #ListGetAt(temp, randtemp)#>
    <cfloop condition="#NewNum# EQ #RANDNUMBER#">
      <CFSET randtemp = #RandRange(1,tempnum)#>
      <CFSET #RANDNUMBER# = #ListGetAt(temp, randtemp)#>
    </cfloop>
    <cfquery name="qryStores" datasource="#DSN3#">
      SELECT     tblStores.pkStoreID, tblStores.StoreName,
tblStores.StoreDesc, tblStores.StoreLogo,
                 tblStores.URL, tblStores.TierID, tblSubCategories.CatID,
tblSubCategories.pkSubCatID
      FROM       tblStores
      INNER JOIN tblStoresSubCatsLink ON tblStores.pkStoreID =
tblStoresSubCatsLink.StoreID
      INNER JOIN tblSubCategories ON tblStoresSubCatsLink.SubCatID =
tblSubCategories.pkSubCatID
      WHERE      tblStores.pkStoreID = #RANDNUMBER#
    </cfquery>
    <tr>
      <td valign="top"><a
href="get_store.cfm?Store=#qryStores.pkStoreID)"><img
src="images/#qryStores.StoreLogo#.jpg" height="125" width="125"></a></td>
      <td valign="top">#qryStores.StoreDesc#...<a
href="store.cfm?StoreID=#qryStores.pkStoreID#" class="ShopNow">SHOP
NOW</a></td>
    </tr>
    <cfset NewNum = #RANDNUMBER#>
  </cfloop>
</table>
</CFOUTPUT>

I tried to use #NewNum# to check to see if a dupe was being made,
unfortunately, that method only works when you work with just 2 records, any
more than that and you will sometimes get a dupe.

Tried to store (and grow) a list of #RandNumber#'s generated, and compare
that to the currently generated #RandNumber# - if dupe found, keep creating
#RandNumber# until no duplicate...  Didn't work, resulted in an endless loop
i think, or a very slow one...

This would be SO much easier if SQL Server or Cold Fusion could randomly
select 5 records from a query with a simple command...sigh....

Thanks in advance,

Dan Slater


-------------------------------------------------------------------------
This email server is running an evaluation copy of the MailShield anti-
spam software. Please contact your email administrator if you have any
questions about this message. MailShield product info: www.mailshield.com

-----------------------------------------------
To post, send email to [EMAIL PROTECTED]
To subscribe / unsubscribe: http://www.dfwcfug.org

Reply via email to