473,698 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

random database result return asp

229 New Member
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 1420
jhardman
3,406 Recognized Expert Specialist
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 New Member
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 Recognized Expert Specialist
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
6249
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 using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
36
5982
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 than b. So can someone provide a *proper* macro (or function) that returns a random integer between (actually in) a range of values? For example randint(0, 999) could return:
15
2535
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 http://web2jo.com/Work/Random_Temp.html
12
5225
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 RAND(). any ideas? I suppose I could use the current rancom number as the seed for the next random number. but would that really work?
12
3220
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 without success. for example if the number is 123 456 : i would like to have some random strings like theese : (12 * 10 000) + (345 * 10) + (6*1) or (123*1 000)+(4*100)+(5*10)+(6*1) etc...
7
7874
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 details of the categories are stored in another table called Category. What I need to do is retrieve a recordset that contains one record from each category, but where the records that are retrieved are random. I know how to retrieve one or more...
1
338
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I generate a random integer from 1 to N? ----------------------------------------------------------------------- function Random(x) { return Math.floor(x*Math.random()) } gives a random integer in the range from 0 to x-1 inclusive; use « Random(N)+1 » for 1 to N where N>2. ...
3
2081
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: ************************************************* Function RandomString(size as integer, lowerCase as boolean) as string Dim builder as StringBuilder = new StringBuilder() Dim random as Random = new Random() Dim i as integer dim ch as char
3
5303
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" #include <stdlib.h> #include <string.h> #define MAX_PWD_LEN 128
15
2727
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 pick from a list a random element that satisfies a given property. All or none of the elements may have the property. Most of the time, many of the elements will satisfy the property, and the property is a bit expensive to evaluate. Chance of...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.