Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <h3>In your PHP</h3> <p>Use whichever MySQL API you are using already to execute the query. Using the old <code>mysql_*()</code> functions would look like the following. (<em>Note: use of the <code>mysql_*()</code> 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...</em>)</p> <pre><code>// 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); } </code></pre> <h3>Later in your HTML/JavaScript output</h3> <p>Output the JSON string (your array) into the JavaScript on your page:</p> <pre><code>function rotateEvery(sec) { // The JSON from PHP output here // Would look something like // ["Event 1","Event 2","Event 3"] var Quotations = &lt;?php echo $events; ?&gt;; var which = Math.round(Math.random()*(Quotation.length - 1)); document.getElementById('textrotator').innerHTML = Quotation[which]; setTimeout('rotateEvery('+sec+')', sec*1000); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload