Scrolling News Panel

Posted on 2005-04-19
Last Modified: 2008-03-04

I'm looking to create a news panel that will scroll news items that are entered into it. I want the news to stop when you put your mouse over it, but continue when the mouse is off the box.

The second part, I want people to be able to log in and update or remove the news items in the news panel. I wanted to use PHP and MySQL for this.

I believe most of the javascript code is done here:

However, I could't get it running. I think the main problem is just setting something up with PHP to display the news.

Can anyone help me to get this going?

Question by:gregca80
    LVL 7

    Expert Comment

    Define "Couldn't get it running".

    Did it scroll? Start here.

    Did it not scroll: Start in Javascript help.

    Generically speaking, it should be a matter of pulling data from the database and properly escaping it in JS.
    LVL 7

    Expert Comment

    $c= mysql_connect('locahost','you','yourpassword');

    $news = mysql_query("select * from news order by id desc",$c);

    if ($news=mysql_fetch_assoc($news)) {
    echo "<div id=\"news\">

    } else { echo mysql_error(); }

    // OK, so this is really sloppy code, and squinky is going to roe-sham-bo me for it. But this illustrates the point. I'm standing in front of a server rack, and my feet hurt.

    LVL 3

    Expert Comment

    start here.

    $con = mysql_connect("localhost","username","password");

    $sql = "SELECT newsTitle from News";
    $result = mysql_query($sql);

       while ($row = mysql_fetch_array($result)) {
        $newsitem .=$row['newsTitle']."<br>";      

    Html tag to scroll

    <marquee onmouseover="this.stop()" onmouseout="this.start()" scrollAmount="4" scrollDelay="150" direction="up" height="100"><?=$newsitem?></marquee>

    Hope this helps.

    Author Comment

    I ended up doing this:

                 $db= mysql_connect('localhost','un','pw');                    
                 $result = mysql_query("select msg_text from message",$db);
                 while ($myrow = mysql_fetch_array($result)){

    Is there any reason that this code wouldn't be good?

    I only have one row, so I just printed the array position of 0.

    Seems to be doing a fine job for me.

    LVL 7

    Accepted Solution

    Well, if you want to be that way about it, do it this way:

    <?       $db= mysql_connect('localhost','un','pw');                  
              echo mysql_result(mysql_query("select msg_text from message",$db),0);


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now