You'll have to retrieve the content from your DB, and then use it to write your JS array. This is a little bit hacky, but part of the problem is how the js is written - it's in the global scope, and some functionality is tacked on, etc.. This will work.
It will depend on your schema, but selecting the data will look something like
PHP Code:
<?php
# connect to your database
$DB = new mysqli( 'your-database-host','username','password','table-name' );
# get the content of each of your messages
$result = $DB->query( "SELECT `content` FROM `message`" );
if( $result ){
# loop over results
while( $row = $result->fetch_row() ){
# write each item for your js array
$messages[] = addslashes( $row[0] );
}
# then, combine those items into a JS array
$js_array = "var fcontent = ['". implode( "','",$messages ) ."'];";
# note, this is a string representation of a javascript statement.
# it'll look a bit like this:
/*
var fcontent = ['first message','another message','and so forth'];
*/
# ...which is exactly what we need for the javascript.
# two "gotchas":
# 1) this will need to be output to the document _before_ you call the fadingscroller script (otherwise, it "won't exist yet" when the page tries to use it).
# 2) in the fadingscroller script, you need to _remove_ the lines where `fcontent` is defined (otherwise, our fcontent will be overwritten).
}
else{
/* the query failed, do something else */
}
All in all, not that elegant. But the alternative is to rewrite the script (which certainly could [probably should] be done, but I don't know if you want to get into that right now. I'll tinker with it in my free time).
Bookmarks