Search code examples
javascriptmarquee

PHP Dynamic Marquee scroll items one at a time


I have created a function which grabs news titles from a table and scrolls the titles in a marquee.

It works as intended except for the point where it's not scrolling them one at the time but all at the same time.

Here is the code:

$query = mysql_query("SELECT * FROM `news`");

    echo '<ul>';

    while (($row = mysql_fetch_assoc($query)) !== false) {

        $title = $row['title'];


        echo '<li>';
        echo '<marquee behavior="scroll" direction="left">News: '.$title.'</marquee>';
        echo '</li>';

}

How can I get it to scroll the titles 1 at a time instead of the current All at the same time?


Solution

  • This is just the default behaviour of a marquee element in HTML. It scrolls whatever you put into it, there's no way to influence this from the PHP side. By the way, is not in the HTML standard, so your document won't be valid HTML if you use it.

    Therefore, I would advise you to search for a plug-and-play Javascript marquee control online. These usually also offer more sophisticated options.