Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:46:08+00:00 2026-06-07T18:46:08+00:00

I just started learning PHP, and have been trying to build a website to

  • 0

I just started learning PHP, and have been trying to build a website to learn. I found a javascript script that rotates text on the internet here which looks like:

    <script language="JavaScript">

    function rotateEvery(sec)
    {
    var Quotation=new Array()

    // QUOTATIONS
    Quotation[0] = 'First quotation';
    Quotation[1] = 'Second quotation';
    Quotation[2] = 'Third quotation';
    Quotation[3] = 'Fourth quotation';
    Quotation[4] = 'Fifth quotation';
    Quotation[5] = 'Sixth quotation';
    Quotation[6] = 'You can add <b>as many</b> quotations <b>as you like</b>';

    var which = Math.round(Math.random()*(Quotation.length - 1));
    document.getElementById('textrotator').innerHTML = Quotation[which];

    setTimeout('rotateEvery('+sec+')', sec*1000);
    }
</script>

I also have a database table called events that has three fields ( id, when, tag) When is a date, tag is the description of the event (e.g Christmas Party/Halloween at my house).

What i am trying to do is select the events that are happening today and put them in my javascript rotator, randomly.

Is this possible? How would I go about implementing this? I know I am really bad at explaining my questions so if I left out any more details if you could just tell me and I can help.Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:46:09+00:00Added an answer on June 7, 2026 at 6:46 pm

    So if I understand your intent, you want to pull events from your database and pass them into the JavaScript on your page to use in your rotator:

    In your PHP

    Use whichever MySQL API you are using already to execute the query. Using the old mysql_*() functions would look like the following. (Note: use of the mysql_*() functions is actually NOT recommended, but it seems most likely that’s what you’re currently using. I’ll update if I find out otherwise…)

    // Assuming `when` is a real DATE or DATETIME data type in MySQL...
    // compare to CURDATE() to get today's
    $result = mysql_query("SELECT tag FROM events WHERE DATE(when)=CURDATE()");
    if ($result) {
      // array to hold all the output
      $events = array();
      while ($row = mysql_fetch_assoc($result)) {
        // Add the event to your array
        $events[] = $row['tag'];
      }
      // After building the array, encode it as JSON
      // Later you'll echo this into your JavaScript in place of the array...
      $events = json_encode($events);
    }
    

    Later in your HTML/JavaScript output

    Output the JSON string (your array) into the JavaScript on your page:

    function rotateEvery(sec)
    {
      // The JSON from PHP output here
      // Would look something like
      // ["Event 1","Event 2","Event 3"]
      var Quotations = <?php echo $events; ?>;
    
      var which = Math.round(Math.random()*(Quotation.length - 1));
      document.getElementById('textrotator').innerHTML = Quotation[which];
    
      setTimeout('rotateEvery('+sec+')', sec*1000);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning coding and PHP so I have been looking at
I just started learning Zend (& OO PHP for that matter), I have spent
I have just started learning PHP, and here's my first doubt... Both of these
I have just started trying to learn Git and I have got a little
I just started learning PHP and I have some questions about the parameters. Consider
I´ve just started learning GWT and I´m trying to implement http://gwt.google.com/samples/Showcase/Showcase.html#!CwFileUpload and but failing
I just started learning Common Lisp a few days ago, and I'm trying to
I have just started learning GWT. My question is pretty simple: If I create
I haven't officially started learning PHP, just skimming through a couple tutorials and I
I'm a hobbyist, and started learning PHP last September solely to build a hobby

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.