Forums

ASP

This topic is locked

HELP! Random record+distinct

Posted 05 Feb 2007 09:46:34
1
has voted
05 Feb 2007 09:46:34 Daniel Beck posted:
Hi,

I have a little problem when im trying to build a page to display banners.

Im not so skilled in ASP and work mostly in DW 8.


Here is the case:

I have a page where I display my banners: biasi.xhosting.se/rklm_list_rand_dist.asp

Its got a simple recordset, repeat region and the Horizontal looper 2 to display 2 colums and 25 rows.

I also added the random record from: www.valleywebdesigns.com/vwd_dw_RR.asp

My problem is that I want the banners to randomize BUT without displaying the same banner twice.

I want to show the Unique banners but in a random way. Not twice on the same page.

Extensions:
www.tom-muck.com/extensions/help/HorizontalLooper/
www.valleywebdesigns.com/vwd_dw_RR.asp

I hope some body can help me.

Thanks so much in advance

Br
DB


Lb

Edited by - digitalvoyager on 06 Feb 2007 11:58:40

Edited by - digitalvoyager on 06 Feb 2007 11:59:06

Replies

Replied 07 Feb 2007 17:52:49
07 Feb 2007 17:52:49 dave blohm replied:
Dont want them to display TWICE or TWICE IN A ROW?
Replied 07 Feb 2007 18:23:43
07 Feb 2007 18:23:43 Daniel Beck replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Dont want them to display TWICE or TWICE IN A ROW?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

I want the banners to display once on every random load. Now the banners can be displayed 2-5 times on the same page.

Lb
Replied 07 Feb 2007 19:08:48
07 Feb 2007 19:08:48 dave blohm replied:
OK...just so that Im clear and give you a proper solution...

You want a page to load with all your logos displayed on it in random order and you want each and every logo to be displayed once and only once on this page.

Is this correct?
Replied 07 Feb 2007 19:13:08
07 Feb 2007 19:13:08 Daniel Beck replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
OK...just so that Im clear and give you a proper solution...

You want a page to load with all your logos displayed on it in random order and you want each and every logo to be displayed once and only once on this page.

Is this correct?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Yes sir <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

That is correct.


Lb
Replied 07 Feb 2007 19:56:08
07 Feb 2007 19:56:08 dave blohm replied:
Try the code below. This does not use the behaviors you mentioned and is <i>much</i> cleaner. I commented it fairly well. Let me know if you have any questions.

<pre id=code><font face=courier size=2 id=code>&lt;%
' ::::: DEFINE OUR VARIABLES LIKE GOOD LITTLE CODERS
dim RsRklm, RsRklm_cmd, i_cols, i_rows, var_max_images, var_cols, var_rows

' ::::: SET MAXIMUM ROWS AND COLUMNS THAT CAN BE DISPLAYED
var_rows = 4
var_cols = 4

' ::::: OPEN THE RECORDSET...NOTICE THE "ORDER BY NEWID()"...THAT'S WHAT RETURNS
' ::::: THE RECORDS IN RANDOM ORDER
Set RsRklm_cmd = Server.CreateObject ("ADODB.Command"
RsRklm_cmd.ActiveConnection = MM_biasi_db_STRING
RsRklm_cmd.CommandText = "SELECT * FROM ban ORDER BY newid()"
RsRklm_cmd.Prepared = true
Set RsRklm = RsRklm_cmd.Execute
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Rklm - annons - Biasi&lt;/title&gt;
&lt;/head&gt;
&lt;body leftmargin="0" topmargin="0"&gt;
&lt;table border="0" cellspacing="0" cellpadding="2"&gt;
&lt;%
' ::::: GENERATE THE ROWS
while ((not RsRklm.eof) and (i_rows &lt; var_rows))
i_rows = i_rows + 1%&gt;
&lt;tr&gt;
&lt;%
' ::::: GENERATE THE COLUMNS
while not RsRklm.eof and i_cols &lt; var_cols
i_cols = i_cols + 1%&gt;
&lt;td align="center" valign="middle"&gt;&lt;a href="/goto_rklm.asp?BAN_ID=&lt;%=(RsRklm.Fields.Item("BAN_ID".Value)%&gt;" target="_blank"&gt;&lt;img src="/rklm_logos/&lt;%=(RsRklm.Fields.Item("BAN_IMAGE".Value)%&gt;" alt="&lt;%=(RsRklm.Fields.Item("BAN_ALT".Value)%&gt;" width="120" height="60" border="0"&gt;&lt;/a&gt;&lt;/td&gt;
&lt;%RsRklm.movenext
wend
i_cols = 0%&gt;
&lt;/tr&gt;
&lt;%if not RsRklm.eof then
RsRklm.movenext
end if
wend%&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
RsRklm.close
set RsRklm = nothing
%&gt;</font id=code></pre id=code>

Edited by - daveblohm on 07 Feb 2007 19:58:29
Replied 08 Feb 2007 12:42:02
08 Feb 2007 12:42:02 Daniel Beck replied:
Hi Dave,

Thanks so much for your help.

But when i try this i get this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Undefined function 'newid' in expression.

/rklm_list_rand_dist2.asp, line 17

Advice?

Thank you

Br
DB<b></b>
Replied 08 Feb 2007 17:16:18
08 Feb 2007 17:16:18 dave blohm replied:
Sorry. Wasn't paying attention. I wrote the SQL statement I gave you for MS SQL. Didn't realize you're using Access.

Change <b><font color=red>RsRklm_cmd.CommandText = "SELECT * FROM ban ORDER BY newid()"</font id=red></b> to <b><font color=green>RsRklm_cmd.CommandText = "SELECT * FROM ban ORDER BY RND()"</font id=green></b> in the SQL statement.

Hope that helps. Let me know...

- Doc

Progress is made by the discontent.
Replied 09 Feb 2007 00:16:19
09 Feb 2007 00:16:19 Daniel Beck replied:
Works Great!!

biasi.xhosting.se/rklm_list_rand_dist2.asp

But it dosent randomize on load? When i update the page.

Thanks in advance.

Br
DB
Replied 10 Feb 2007 09:46:12
10 Feb 2007 09:46:12 Daniel Beck replied:
Hi Dave or anybody,

Any advice on how I can randomize the page on load?
The code works fine but i want it to randomize the list on every OnLoad.

Thanks in advance

DB
Replied 10 Feb 2007 16:17:45
10 Feb 2007 16:17:45 dave blohm replied:
You need to specify a seed value to the RND() function. It looks like your unique record
identifier is BAN_ID so let's try that.

RND(BAN_ID)

- Doc

Progress is made by the discontent.

Reply to this topic