473,383 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

random database result return asp

229 100+
Hi, Anyone know how to adjust this so that the results appear in a random order? is it in the "Order By PostCardID DESC" part?

Expand|Select|Wrap|Line Numbers
  1. ..asp
  2.  
  3. <!--#Include File="art/dbconnect.asp"-->
  4. <%
  5.  
  6.  
  7. lngCategoryID=CLng(Request("CategoryID"))
  8. If lngCategoryID <> "" And lngCategoryID <> 0 Then
  9.  
  10.     Set connPostCardSoft=Server.CreateObject("ADODB.Connection") 
  11.     connPostCardSoft.Open PostCardSoftConnectString
  12.     Set rsCard=Server.CreateObject("ADODB.Recordset")
  13.     rsCard.CursorLocation = 3
  14.     SQLQuery="Select PostCardID,DefaultHeadline,CardDescription,DefaultMessage,Author,ThumbnailURL,AdvancedCard,ThumbnailHTML From tblGreetingPostCards Where CategoryID=" & Clng(lngCategoryID) & " Order By PostCardID DESC"
  15.     rsCard.Open SQLQuery, connPostCardSoft
  16.        rsCard.PageSize = 200
  17.        intPageCount = rsCard.PageCount
  18.  
  19.     If rsCard.EOF=True Then
  20.         Response.Write "<p>No cards found in database for this category."
  21.         Response.End
  22.     End If
  23. End If
  24.  
  25. 'search feature
  26. If Request("SearchWord") <> "" Then
  27.     strWd=Replace(Request("SearchWord"),"'","''")
  28.     strSQL="Select PostCardID,DefaultHeadline,CardDescription,DefaultMessage,Author, "
  29.     strSQL=strSQL & " ThumbnailURL,AdvancedCard,ThumbnailHTML From tblGreetingPostCards Where Keywords Like '%" & strWD & "%' OR "
  30.     strSQL=strSQL & " DefaultHeadline Like '%" & strWD & "%' OR "
  31.     strSQL=strSQL & " CardDescription Like '%" & strWD & "%' OR "
  32.     strSQL=strSQL & " Author Like '%" & strWD & "%' OR "
  33.     strSQL=strSQL & " DefaultMessage Like '%" & strWD & "%' "
  34.  
  35.     Set connPostCardSoft=Server.CreateObject("ADODB.Connection") 
  36.     connPostCardSoft.Open PostCardSoftConnectString
  37.     Set rsCard=Server.CreateObject("ADODB.Recordset")
  38.     rsCard.CursorLocation = 3
  39.     rsCard.Open strSQL, connPostCardSoft
  40.        rsCard.PageSize = 200
  41.        intPageCount = rsCard.PageCount
  42. End If
  43.  
  44. strAddition="bgcolor=" & Chr(34) & Application("gcp_SearchPageBackgroundColor") & Chr(34)
  45. strCategoryBarFontColor=Application("gcp_SearchPageFontBarColor")
  46. strCategoryBarColor=Application("gcp_SearchPageBarColor")
  47.  
  48. 'Retrieve Category Name
  49. If lngCategoryID <> "" and lngCategoryID <> 0 Then
  50.     Set rsCat=connPostCardSoft.Execute("Select * From tblGreetingCategories Where CategoryID=" & Clng(lngCategoryID))
  51.     strCat="" & rsCat("CategoryName")
  52.  
  53.     If rsCat("CategoryBackgroundImage")<> "" Then
  54.         strAddition="background=" & Chr(34) & rsCat("CategoryBackgroundImage") & Chr(34)
  55.     End If
  56.     If rsCat("CategoryBackgroundColor")<>"" Then
  57.         strAddition="bgcolor=" & Chr(34) & rsCat("CategoryBackgroundColor") & Chr(34)
  58.     End If
  59.     strCategoryBarFontColor=rsCat("CategoryBarFontColor")
  60.     strCategoryBarColor=rsCat("CategoryBarColor")
  61.     FontName=rsCat("FontName")
  62.     FontColor=rsCat("FontColor")
  63. Else
  64.     strCat="Search results for:" & strWD
  65.     FontName=Application("gcp_FontName")
  66.     FontColor=Application("gcp_FontColor")
  67. End If
  68.  
  69.  
  70.    Select Case Request("Action")
  71.            case "  <<  "
  72.                    intpage = 1
  73.            case "  <  "
  74.                    intpage = Request("intpage")-1
  75.                    if intpage < 1 then intpage = 1
  76.            case "  >  "
  77.                    intpage = Request("intpage")+1
  78.                    if intpage > intPageCount then intpage = IntPageCount
  79.            Case "  >>  "
  80.                    intpage = intPageCount
  81.            case else
  82.                    intpage = 1
  83.                    If Request.QueryString("intpage") <> "" Then
  84.                        intpage=Request.QueryString("intpage")
  85.                    End If
  86.    end select
  87.  
  88.  
  89.  
  90. %>
  91.  
  92.  
  93.  
.. asp


Thanks
Richard
Jul 31 '07 #1
3 1410
jhardman
3,406 Expert 2GB
I don't think sql can be done random. You could try putting all the results in a set of arrays, and then accessing them randomly... Let me know if this helps.

Jared
Aug 2 '07 #2
fran7
229 100+
Thanks for replying,
The answer I found was that this works. Changing this string

Expand|Select|Wrap|Line Numbers
  1. ..code asp
  2.  
  3.     SQLQuery="Select PostCardID,DefaultHeadline,CardDescription,DefaultMessage,Author,ThumbnailURL,AdvancedCard,ThumbnailHTML,Rnd([PostCardID]) From tblGreetingPostCards Where CategoryID=" & Clng(lngCategoryID) & " Order By Rnd([PostCardID])"
  4.  
  5.  
..code asp

Thanks
Richard
Aug 3 '07 #3
jhardman
3,406 Expert 2GB
Thanks for replying,
The answer I found was that this works. Changing this string

Expand|Select|Wrap|Line Numbers
  1. ..code asp
  2.  
  3.     SQLQuery="Select PostCardID,DefaultHeadline,CardDescription,DefaultMessage,Author,ThumbnailURL,AdvancedCard,ThumbnailHTML,Rnd([PostCardID]) From tblGreetingPostCards Where CategoryID=" & Clng(lngCategoryID) & " Order By Rnd([PostCardID])"
  4.  
  5.  
..code asp

Thanks
Richard
thanks for posting your solution! It looks like I have more to learn.

Jared
Aug 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
36
by: Michael B Allen | last post by:
Someone once posted the following macro on clc: #define randint(a,b) (a)+(((b)-(a)+1)*(float)rand()/RAND_MAX) Unfortunately it's flawed. If rand() returns RAND_MAX the result can be one larger...
15
by: Papajo | last post by:
Hi, This script will write a random number into a document write tag, I've been trying to get it to write into a input form box outside the javascript, any help is appreciated. Thanks Joe ...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
7
by: FrankEBailey | last post by:
I'm not sure if this is a completely dumb question, but please humor me :) I have a table of records, called Records, each of which has a Category_ID that places it in a specific category; the...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N?...
3
by: tshad | last post by:
I have a page that I am getting a username and password as a random number (2 letters, one number and 4 more letters) I have 2 functions I call: *************************************************...
3
by: Army1987 | last post by:
Is there anything wrong with this program? It seems to behave strangely if I give stdin EOF when asked for the character set... /* BEGIN pwdgen.c */ #include <stdio.h> #include "random.h"...
15
by: caca | last post by:
Hello, This is a question for the best method (in terms of performance only) to choose a random element from a list among those that satisfy a certain property. This is the setting: I need to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.