...

View Full Version : ORDER by random



CurtWRC
02-18-2006, 01:23 AM
Is there a way of ordering a selected database randomly?
If so does anyone know the string I would have to use for this?

Thanks.

vinyl-junkie
02-18-2006, 03:08 AM
There is no Order By Random kind of clause if that's what you're asking. What exactly are you trying to do?

CurtWRC
02-18-2006, 11:26 AM
There is no Order By Random kind of clause if that's what you're asking. What exactly are you trying to do?
I didn't think there would be that kind of clause. I want to select the database and order it in a random order. I will only be displaying the first row on my homepage so that I can display an image which links to a full size version on another page.

Thanks.

vinyl-junkie
02-18-2006, 04:32 PM
Will you be displaying things in random order or just selecting the first record randomly? If selecting the first record randomly, by an id for example, just come up with a random number generator and select the one record using that random number.

What language are you using to code your page?

CurtWRC
02-18-2006, 06:50 PM
Will you be displaying things in random order or just selecting the first record randomly? If selecting the first record randomly, by an id for example, just come up with a random number generator and select the one record using that random number.

What language are you using to code your page?

Im using VB

I would prefer not to do it that way because I have deleted records, so some IDs are missing.

vinyl-junkie
02-18-2006, 07:07 PM
I'm thinking off the top of my head here, but I think you could load all your records into an array, then randomly pick one record from the array for display.

Brandoe85
02-20-2006, 09:51 PM
Are you using access? If so, have a look at the Rnd() (http://www.techonthenet.com/access/functions/numeric/rnd.php) function.

Good luck;

CurtWRC
03-01-2006, 05:39 PM
I may be wrong but wouldn't this just be selecting a random number between certain values. So if I had deleted a record with ID of 8, then if 8 was randomly selected nothing would appear :confused:

luckycharm
12-05-2006, 07:11 PM
I'm assuming your using coldfusion. So if you are, his might be usefull:

________________________________________________________________

<!---first set the query --->
<cfquery name="rs" datasource="#dsn#">
SELECT [column_names(s)]
FROM [table_name]
</cfquery>


<!--- then use the output to display randomly --->
<cfset displayRow = randRange(1,rs.recordcount)>
<cfoutput query="rs" startrow="#displayRow#" maxrows="1">
-- show the random record
</cfoutput>



Hope this helps.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum