Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2003, 03:40 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default Random News Topic when the page loads

    if not Session("donotdo") = 1 then
        SQLStr="SELECT TOP 10 * FROM ORArticles WHERE ORDER by MagID DESC"
        Set RS=Server.CreateObject("ADODB.Recordset")
        RS.Open SQLStr,Application("DBConn"),adOpenKeyset,adLockPe ssimistic,adCmdText
    else
        SQLStr="SELECT TOP 10 * FROM ORArticles WHERE ArticleID=" & Session("GlobalArticleID") & " ORDER by MagID DESC"
        Set RS=Server.CreateObject("ADODB.Recordset")
        RS.Open SQLStr,Application("DBConn"),adOpenKeyset,adLockPe ssimistic,adCmdText
    end if

This code was already present, it only brings up the same article everytime, I want it to choose a random article every time the page is loaded. Is there something that can be added to the code to change articles??

Thanks

__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
 
Old November 19th, 2003, 07:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What database are you using? If you're using SQL Server, you can try this:

SELECT TOP 10 Column1 FROM MyTable ORDDER BY NewID()

This will generate a GUID for each record, and order by that GUID.


HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 19th, 2003, 07:50 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well hot dog!

I hadn't thought of that one! That works pretty well!

Great call Imar!

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 19th, 2003, 10:32 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you I will give it a try, and it is an SQL DB

Thanks again

 
Old November 21st, 2003, 01:38 PM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks guys it works great :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Separating news from the articles and add news pic Isaak BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 December 12th, 2006 11:25 AM
drop down list opens dynamically when page loads robear Javascript How-To 5 April 21st, 2006 10:05 AM
Is this topic a professional topic?? mega ASP.NET 1.0 and 1.1 Professional 0 December 3rd, 2004 09:37 PM
Generate a random article when page loads morpheus SQL Server ASP 1 October 28th, 2003 10:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.