Search code examples
phpmysqlhtmlcssmarquee

displaying mysql data in marquee


i want to make an news bar, by selecting mysql data and display it in and marquee, the problem that all the data are displayed at the same time in different lines, what i need is to display the data line by line. code:

$news = mysql_query("SELECT ann_title, ann_text FROM o_postnews_conference");
         while ($row = mysql_fetch_assoc($news)) {
             echo "<marquee style='float:bottom;'><font color='snow'>{$row['ann_title']}: {$row['ann_text']}</font></marquee>";

Solution

  • It's because you're creating a new marquee element every iteration of your while loop. Use something like the below code instead.

    $news = mysql_query("SELECT ann_title, ann_text FROM o_postnews_conference");
       echo "<marquee style='float:bottom;'><font color='snow'>";      
       while ($row = mysql_fetch_assoc($news))
                 echo "{$row['ann_title']}: {$row['ann_text']} ";
       echo "</font></marquee>";
    

    Although you should know that marquee has been deprecated and you should be using CSS3/javascript instead.