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 January 5th, 2004, 11:00 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default Random featured Articles

SQLStr="SELECT TOP 10 * FROM ORArticles WHERE featured = 1 and MagID = 16"

I have this code, and I have ten articles that are featured(featured = 1), but it only picks the first one, I want it to pick a random article everytime out of the top 10. what do I need to add to the code to have it choose a random aritcle from those 10?

Thanks

__________________
-----------------------------------------------------------
\"Don\'t follow someone who\'s not going anywhere\" John Mason
 
Old January 5th, 2004, 11:25 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What is your database platform? If you are using MSSQL you could do this:

SELECT TOP 1 * FROM ORArticles WHERE featured = 1 and MagID = 16 ORDER BY NEWID()

NEWID() will generate a new GUID for every row selected and because GUIDs are kinda-sorta randomish you'll get a "random" row.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old January 5th, 2004, 11:28 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 166
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That works great, thank you!







Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrox.com C# articles jminatel C# 2005 0 March 23rd, 2007 08:43 PM
Recent articles not showing on articles page kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 December 16th, 2006 10:06 AM
error on articles kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 4th, 2006 02:42 PM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





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