|
| |
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
Trouble randomizing db results in a row - 1/25/2010 23:21:33
Hi, I have used the forums to help me get pictures pulled from my database to appear in a row across the page. However, i would like these results to be randomly ordered each time the page is loaded and am having trouble doing so. Can anyone help? Here is the code:
<center><table>
<!--#include file="_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM listings ORDER BY RND(ID)"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="louisvilleguide"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_iDisplayCols=1
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<%If x = 0 then %>
<tr>
<%end if%>
<%x=x+1%>
<TD> <a href="businessdetail.asp?ID=<%=FP_FieldVal(fp_rs,"ID")%>"><img border="0" src="banners/<%=FP_FieldVal(fp_rs,"name")%>"></a>
<% If x < 4 then %>
</td>
<%Else
x = 0%>
</td></tr>
<%end if%>
<!--#include file="_fpclass/fpdbrgn2.inc"-->
</table>
<!--webbot bot="PurpleText" PREVIEW="Code" -->
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 1/26/2010 11:56:24
Thanks, but this is the error i got..... Database Results Error Description: Undefined function 'NewID' in expression. Number: -2147217900 (0x80040E14) Source: Microsoft JET Database Engine
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 1/26/2010 14:46:35
Thanks...the only problem is i want them all to display in random order....not display just one random result. Anybody know why i'm getting that error?
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 1/26/2010 17:59:03
I'm trying this now...but still not random <% ' Initialize ASP RND() function Randomize() intRandomNumber = Int (1000*Rnd)+1 fp_sQry= _ "SELECT TOP 1000 ID, realname, name, Rnd(" & -1 * (intRandomNumber) & "*ID)" & _ "FROM listings " & _ "ORDER BY RND()" fp_sDefault="" fp_sNoRecords="No records returned." fp_sDataConn="louisvilleguide" fp_iMaxRecords=256 fp_iCommandType=1 fp_iPageSize=0 fp_fTableFormat=False fp_fMenuFormat=False fp_sMenuChoice="" fp_sMenuValue="" fp_iDisplayCols=1 fp_fCustomQuery=False BOTID=0 fp_iRegion=BOTID %>
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 1/26/2010 18:49:52
No there are 6 but more will be added so i wanted to cover them too.....i changed to 6 to no avail...also ORDER BY was originally 3 from the code snippet. I'll post my code and the snippet below
<%
' Initialize ASP RND() function
Randomize()
intRandomNumber = Int (6*Rnd)+1
fp_sQry= _
"SELECT TOP 6 ID, realname, name, Rnd(" & -1 * (intRandomNumber) & "*ID)" & _
"FROM listings " & _
"ORDER BY 3"
fp_sDefault=""
fp_sNoRecords="No records returned."
fp_sDataConn="louisvilleguide"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=False
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_iDisplayCols=1
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
Microsoft Access
For Microsoft Access we can return a set of one or more random records by using the RND() function to order the resultset. The only difficulty is that the RND() seed is cached resulting in the same ordered set of results if we use RND() directly in the SQL statement.
To get around this we pass in a different value to the RND() function each time, forcing Access to use a new seed when generating the random number. Assume that we have a table called: Table1 and this contains fields: TableID and Field1
<%
' Initialize ASP RND() function
Randomize()
intRandomNumber = Int (1000*Rnd)+1
' Return 3 random records
strSQL = _
"SELECT TOP 3 TableID, Field1, Rnd(" & -1 * (intRandomNumber) & "*TableID)" & _
"FROM Table1 " & _
"ORDER BY 3"
Set objRS = objConn.Execute(strSQL)
%>
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 1/29/2010 12:39:35
Thanks...this is as close as i've come. How can i show ALL records with room to grow? I tried entering like 10k and it showed all but they didn't randomize when refreshed. I feel i'm soooo close...thanks again!
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 1/29/2010 14:42:56
Hey Spooky, do you have a code sample that uses the new drivers? I don't know much about the drivers...does that have anything to do with the version of access or just how it is called in the code?
|
|
|
|
jonance
Posts: 316 From: Louisville KY USA Status: offline
|
RE: Trouble randomizing db results in a row - 2/2/2010 13:40:08
Ok...i changed to the new code in global.asa, but i get this error now: Database Results Error Description: Undefined function 'NewID' in expression. Number: -2147217900 (0x80040E14) Source: Microsoft JET Database Engine
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|