HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 12th, 2004, 09:30 AM
igotdamaged igotdamaged is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 igotdamaged User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Selecting Random News Stories

Hello everyone.

I am trying to put together a "news area" for my website.

Basically, I want to have a bank of 20 news stories, but I would like to display just the headlines of 5 of them within this news area.

My problem is that I would like the 5 stories to be selected at random.

Does anyone have a bit of code, or a link to an article that would do this?

I'd prefer to so this as simply as possible, and ideally without using a database.

Thanks for your time.

IGD

Reply With Quote
  #2  
Old February 15th, 2004, 08:33 PM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
You could do this with ASP or Javascript. Let's say you have 20 news titles. Create an array with 20 titles. Then add your titles to the array:

Dim Array1
Array1(0) = "Title of news 1";
Array1(1) = "Title of news 2";
...and so on...

Then loop 5 times to display the news titles:

For i = 1 to 5
Randomize ' Initialize random-number generator.
x = Int((20 * Rnd) + 1) ' Generate random value between 1 and 20.
Response.write( Array1(x) )
Next

Of course, you'll have to add some code to ensure that you don't display the same title twice.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > Selecting Random News Stories


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway