Jump to content

[SOLVED] help with setInterval


CyberShot

Recommended Posts

I have small script to generate a random quote when the page loads. It works. I decided to use javascript to refresh the div the code sits in every 10 seconds so that every quote would display if you were on the page for a while. My problem is that when the page loads, the div the quote sits in is empty and then after the given time, one quote will show up but it does not change. Here is my code

 

<?php
class quotes
{
function quotes() {
	switch(intval(rand(1,5)))
	{
		case 1:
			$this->quote = "A computer once beat me at chess, but it was no match for me at kick boxing 
-Emo Philips" ;
			break;
		case 2:
			$this->quote = "It was when I found out I could make mistakes that I knew I was on to something -Ornette Coleman" ;
			break;
		case 3:
			$this->quote = "You can't build a reputation on what you're going to do -Henry Ford";
			break;
		case 4:
			$this->quote = "People are just as happy as they make up their minds to be -Abraham Linkcoln";
			break;
		case 5:
			$this->quote = "Good advice is something a man gives when he is too old to set a bad example -Francois de La Rochefoucauld ";
			break;
	}
}
}

		$quotes = new quotes();
		echo $quotes->quote;

?>

 

and the jquery to run it

 

function randomQuote(){
   $('#rand').load('includes/quotes.php');
   }
   $(document).ready(function(){
   setInterval("randomQuote()", 1000);

});

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.