|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Selecting Random News Stories |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|