EDIT: I'm new here and for some reason, it looks like I created two threads. How do I delete one?
Hi, I have a mysql select from database when the date is today that I then put into a javascript text rotator. Unfortunately, it isn't displaying anything. Why would that be?
PHP Code:
include("config.php");
$result = mysql_query("SELECT * FROM events WHERE 'when' = CURDATE()");
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
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);
}
echo $events;
?>
<script type='text/javascript'>
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);
}
</script>