Ask a Question related to Coldfusion Database Access, Design and Development.
-
SMRieth #1
Random Pulls
Good day. I am using an MS Access database.
In one table I will have an unknown number of entries. What I would like to
do is pull five unique, random entries and display them. The idea is to pull
five random links from a table of URLs and display them (again, ensuring no two
displayed links are alike).
Any suggestions?
Thank you for your time!
SMRieth Guest
-
Creating a page that pulls from a table
I want to create a page that will dynamically pull information from a single table when querried by a single record. I don't want it to display any... -
Server pulls pages from wrong directory
Hi, We're having a very strange issue. We just upgrade to Coldfusion 6.1, and now it is at random displaying the wrong pages. Particularly, we... -
need ftp-mirroring software, that pushes, rather than pulls
Hello! I need to push a sizable subtree over to another server periodically. The remote, however, only allows ftp... All of the... -
Using Math.random to go to random frames
Hello everyone. My cerebral density is preventing me from seeing the solution to this problem. I have the following code which causes the user to... -
Random image in a random place.
Anyone know javascript? I have a grid(4 x 4) of 16 spacer images and a few text links on the side. Each text link represents a different folder of... -
Mountain Lover #2
Re: Random Pulls
SELECT yourfields
FROM yourtable
WHERE yoursearchcriteria
ORDER BY RND(youruniqueidfield)
HTH
--
Tim Carley
[url]www.recfusion.com[/url]
[email]info@NOSPAMINGrecfusion.com[/email]
Mountain Lover Guest
-
mxstu #3
Re: Random Pulls
Originally posted by: Newsgroup User
SELECT yourfields
FROM yourtable
WHERE yoursearchcriteria
ORDER BY RND(youruniqueidfield)
I would also make that .... SELECT TOP 5 yourFields .... to limit the
returned results to 5 records.
mxstu Guest
-
mxstu #4
Re: Random Pulls
Mountain Lover,
What version of Access/MX are you using? I'm not really that up on Access,
but I know this technique worked in previous CF versions. Yet it doesn't seem
to randomize the records when used with CFQUERY, Access 2000 and MX 6.1.
mxstu Guest
-
SMRieth #5
Re: Random Pulls
I have tried the usual SQL pulls that have been suggested, but they do not
provide the random pull that I am looking for; they only pull the top 5
entries. I can pull five random entries between CFML and SQL, but I can't
figure out how to make them unique without what is probably excessive code (a
bunch of IF THEN or CASE statements).
I use MS Access 2003.
SMRieth Guest
-
Mountain Lover #6
Re: Random Pulls
>
CF5, CF6.1 & CF 7 & Access 2000. Yeah you are right, it doesn't> What version of Access/MX are you using?
randomize anymore in CFMX (6&7), CF 5 works perfectly. Gotta' love what
those JAVA drivers did for the M$ Access connection! :(
So something like this will get one random value... should work in CFMX
(untested)
random_element = RandRange(1, queryname.RecordCount);
random_value = queryname.columnname[random_element] ;
you'll need to loop through the query to make a list of 5
Or maybe this:
[url]http://www.cflib.org/udf.cfm?id=524&enable=1[/url]
HTH
--
Tim Carley
[url]www.recfusion.com[/url]
[email]info@NOSPAMINGrecfusion.com[/email]
Mountain Lover Guest
-
BKBK #7
Re: Random Pulls
>... What I would like to do is pull five unique, random entries
In spite of the simplicity of this statement, I do believe that it is an exceedingly
difficult problem to solve.
BKBK Guest
-
mxstu #8
Re: Random Pulls
Originally posted by: Newsgroup User
Or maybe this:
[url]http://www.cflib.org/udf.cfm?id=524&enable=1[/url]
Mountain Lover,
I think the UDF would probably work here, if the OP just needs to display 5
random records each time a page is loaded. Of course your original query idea
was better ;-)
<---- NEED TO DOWNLOAD QueryRandomRows() UDF from cflib.org ---->
<!--- get distinct "links" --->
<cfquery name="getRecords" datasource="yourAccessDSN">
SELECT DISTINCT theLink
FROM yourTable
</cfquery>
<!--- get 5 random records --->
<cfset randRecords = QueryRandomRows(getRecords, 5)>
<cfdump var="#randRecords#">
mxstu Guest
-
BKBK #9
Re: Random Pulls
>... I think the UDF would probably work here
Anyone have any ideas how the problem can be solved using SQL alone?
That would be neat.
BKBK Guest
-
SMRieth #10
Re: Random Pulls
Thanks to everyone for their help.
I used the longer code I was thinking of before as it seems there is no easier
way to accomplish this.
Basically, I created a second table just to hold the random links. I
generated a random number from 1 up to the total number of links available in
the original table and queried for the link that had an ID that matched the
random number. Then, I ran a query to ensure that ID did not exist in the
second table. If the link did not exist, then it would be entered; if it did
exist, the system will loop until it finds one that doesn't until there are 5
records in the second table.
Oh well, it works. Thanks!
SMRieth Guest
-
BKBK #11
Re: Random Pulls
>... there is no easier way to accomplish this.
This is easy enough, hoping it works. I followed the logic in
[url]http://techrepublic.com.com/5100-9592_11-5796605.html?tag=sc[/url]
/*Assuming your table has column called 'url', of type varchar and non-null*/
CREATE TABLE MyNewTable(PK uniqueidentifier NOT NULL DEFAULT NewID(), url
VARCHAR NOT NULL);
SELECT DISTINCT TOP 5 url, NewID() AS Random
FROM urlTable
ORDER BY Random; DROP TABLE MyNewTable
BKBK Guest
-
Mountain Lover #12
Re: Random Pulls
Unfortunately Access doesn't support NewID(), SQL Server only. And it
works very well in SQL Server.
--
Tim Carley
[url]www.recfusion.com[/url]
[email]info@NOSPAMINGrecfusion.com[/email]
Mountain Lover Guest
-
BKBK #13
Re: Random Pulls
>... Unfortunately Access doesn't support NewID(), SQL Server only.
Oops!
BKBK Guest
-
mxstu #14
Re: Random Pulls
>>This then makes Rnd() a good replacement for MS SQL's NewID().
No. Using Rnd(IDColumn) was the original suggestion by Mountain Lover, but if
you read the thread, you will see that it does not return the anticipated
results in MX 6.1/7, which is what brought on the search for alternative
methods.
If the code is just selecting from "urlTable", what is the purpose of the>>CREATE TABLE MyNewTable(Random FLOAT NOT NULL, url VARCHAR NOT NULL);
>>SELECT DISTINCT TOP 5 url, Rnd(rowNr) AS Random
>>FROM urlTable
>>ORDER BY Random; DROP TABLE MyNewTable
CREATE TABLE statement here? Also, you cannot ORDER BY an alias in Access.
mxstu Guest



Reply With Quote

