Jul 7, 2008

How Do I Mank A Random Quote Come Up Radomly? - if anything is random......

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > HTML, XML etc..

free web hosting

How Do I Mank A Random Quote Come Up Radomly? - if anything is random......

fsastraps
Well i was just wondering b/c i have a lot of quotes that i would like to put on my site, and i was wondering how i could do is so that there are quotes that will come up randomly? If anybody can help me, i would greately appreciate it, thanks.

Reply

no9t9
<?php $rdm=rand(1,3);
if ($rdm==1) $quote="quote text 1";
else if ($rdm==2) $quote="quote text 2";
else if ($rdm==3) $quote="quote text 3";
echo $quote; ?>

the statement $rdm=rand(1,3); basically generates a random number between 1 and 3. Change the 3 to suit your needs.

this will work but may not be ideal if you have A LOT of quotes.

Reply

snlildude87
n09t9's method will not work if you have a huge amount of quotes, so I have just the method for you! Luckily, I asked this question not too long ago, and you can look at my question here: http://www.trap17.com/forums/generate-rand...ases-t8488.html

smile.gif

Reply

round
You didn't mention what kind of script you were looking for so this is javascript one.

Here's your script - copy and paste then name the file quotes.js

function makeArray(len) {
for (var i = 0; i < len; i++) this[i] = null;
this.length = len;
}

// you add as many quotes as you want here just make sure to change the makeArray(number)

ideas = new makeArray(22);
ideas[0] = "1";
ideas[1] = "2"
ideas[2] = "3"
ideas[3] = "4"
ideas[4] = "5"
ideas[5] = "6"
ideas[6] = "7"
ideas[7] = "8"
ideas[8] = "9"
ideas[9] = "10"
ideas[10] = "11"
ideas[11] = "12"
ideas[12] = "13"
ideas[13] = "14"
ideas[14] = "15"
ideas[15] = "16"
ideas[16] = "17"
ideas[17] = "18"
ideas[18] = "19"
ideas[19] = "20"
ideas[20] = "21"
ideas[21] = "22"

// The random number generator.
function rand(n) {
seed = (0x015a4e35 * seed) % 0x7fffffff;
return (seed >> 16) % n;
}
var now = new Date()
var seed = now.getTime() % 0xffffffff




Here's your html doc
<HTML>
<HEAD>
<script src="quotes.js"></script>
</HEAD>
<BODY>

<script LANGUAGE = "JavaScript">
// this you put into you html doc where you want your quotes to appear
document.write(ideas[rand(ideas.length)])
</SCRIPT>

</BODY>
</HTML>

round

 

 

 


Reply

spacemonkey
Here is an easy way to make a random quote or block of HTML code appear on your page quite easily with javascript:

CODE
var a = Math.random() + ""
var rand1 = a.charAt(5)
quotes = new Array
quotes[1] = "QUOTE 1"
quotes[2] = "QUOTE 2"
quotes[3] = "QUOTE 3"
quotes[4] = "QUOTE 4"
quotes[5] = "QUOTE 5"
quotes[6] = "QUOTE 6"
quotes[7] = "QUOTE 7"
quotes[8] = "QUOTE 8"
quotes[9] = "QUOTE 9"
quotes[0] = "QUOTE 10"
var quote = quotes[rand1]
document.write(quote);


Even though this code is simple, there are two downsides to using it: 1. You can only have up to 10 quotes (because the random number is retrieved from a single character in a string of numbers) and 2. Unless you know some Javascript and can do some simple modifications, you would have to place this whole script in the body of your HTML document where you would want it to appear. So you wouldn't be able to call it externally (and would, hence, clutter your HTML). But, like I said before, you could make this script do that. I could change it for you but I am too lazy. I can not be bothered.

Reply

no9t9
if you want to use files (PHP) it is better for A LOT of quotes. I wasn't sure how many you have. IF you save the quotes in a text file (one quote per line). You can use the following code.

<?php
$quote=file("quotes.txt");
$totalnumberofquotes=count($quote);
$rdm=rand(1,$totalnumberofquotes);
echo $quote[$rdm];
?>

Reply

fsastraps
well, thanks for all of theses, but i cant seem to make any of them work. Or is it because they only work from a server and not in my computer? Or do i have to save the file on were im putting them at as an .shtml? i dont know, maybe im just not doing it right.....If someone could help i would appreciate it.
thanks

Reply

no9t9
PHP code does not display in frontpage or other WYSIWYG editors. You should upload the files to your web space.

(1) Save this code directly in your HTML file.

QUOTE
<?php
$quote=file("quotes.txt");
$totalnumberofquotes=count($quote);
$rdm=rand(1,$totalnumberofquotes);
echo $quote[$rdm];
?>


(2) rename the HTML file so that the extension is .php

(3) Upload the file to your webspace

(4) upload the quote.txt file to your webspace (same directory as the php file)

(5) access the php file by typing http://yourwebsite.com/quote.php

Note: if you are putting this code in your index file, you must rename your index.html file to index.php and delete the old index.html or index.htm.

Reply

spacemonkey
QUOTE(no9t9 @ Mar 29 2005, 11:41 PM)
PHP code does not display in frontpage or other WYSIWYG editors.  You should upload the files to your web space.

(1) Save this code directly in your HTML file.
(2) rename the HTML file so that the extension is .php

(3) Upload the file to your webspace

(4) upload the quote.txt file to your webspace (same directory as the php file)

(5) access the php file by typing http://yourwebsite.com/quote.php

Note: if you are putting this code in your index file, you must rename your index.html file to index.php and delete the old index.html or index.htm.
*


This assumes that your web server supports PHP.

Reply

Spectre
Well, I screwed that one up good and proper. Please ignore all of my posts within this thread, and could a moderator please delete the above? Thanks.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. php random quote from textfile - 7.60 hr back.
  2. ideas - 17.92 hr back.
  3. display random quote from text file php - 19.72 hr back.
  4. how to make random quotes in html - 19.81 hr back.
  5. random quote generator for html - 25.24 hr back.
  6. html random quotations - 40.11 hr back.
Similar Topics

Keywords : mank, random, quote, radomly, random

  1. Banner From Single To Random
    (0)


      Looking for mank, random, quote, radomly, random

Searching Video's for mank, random, quote, radomly, random
advertisement



How Do I Mank A Random Quote Come Up Radomly? - if anything is random......



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE