Scrolling text loaded from mysql

This is a piece of code ahmed gave me. It worked fine ! Here I used a textfield called contentText. Just paste a scrollbar component to it and it should work.

[AS]
onClipEvent (load) {
contentText.condenseWhite = true;
contentText.html = 1;
lv = new loadVars();
lv.onLoad = function(success) {
if (success) {
i = this.i; //this.i is the variable loaded, i is the var of a textfield
inhoud.html = 1;
for (l=i; l>=0; l–) {
contentText.htmlText += this[“datum”+l];
contentText.htmlText += this[“inhoud”+l];
/* datum, inhoud and i (the first one, not the one from the for() loop are variables loaded from the database by the PHP script */
}
} else {
trace(“failed to load script”);
}
};
lv.load(“http://www.yourserver.com/script.php”);
}[/AS]

And this is the PHP script, debugged by Jubba :slight_smile: The vars are in a table called ‘yourtable’, inside the database ‘yourdatabase’.


<?
$l = mysql_connect("host", "username","password");
mysql_select_db("yourdatabase");

$q = "SELECT * FROM yourtable";
$r = mysql_query($q, $l);

if($r){
     $nrows = mysql_num_rows($r);

     $output="";

     for ($i=0; $i < $nrows; $i++){
         $row = mysql_fetch_array($r);

         $output .= "&i=".$i;
         $output .= "&datum".$i."=".$row['datum'];
         $output .= "&inhoud".$i."=".$row['inhoud'];
     }
     print $output;
}
else
{
     print mysql_error($l);
}



mysql_close($l);
?>

That should get it working :slight_smile: