Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Posts
    20

    Unanswered: Horizontal Scrolling Text From DB

    Hi guys,
    I've been searching around a bit and can't seem to find a script to display text from a database and scroll it across the page, like a news ticker. I'd like to it display horizontally across the page. I assume that it'll be a mixture of Javascript and PHP, and I've found some versions of it in my search, but nothing that seems to work very well. Any ideas?
    I'm not stuck on PHP or JS, I just need SOMETHING to take the info from my DB and scroll it across the page like a news ticker.

    Thanks!

  2. #2
    Join Date
    Mar 2009
    Posts
    11
    You could use the old tried and still somewhat true: Marquee element. marquee
    Note: The marquee element doesn't have complete support across all browsers and I'd normally say not to use it, but for most browsers, it's fully supported.
    It also can be a bit jerky.
    Flash or Silverlight look the best and of course you can use a JavaScript framework or handcrafted code to good effect.

    // Simple use of marquee...
    Code:
    <html>
    <body>
    <?php
    $dbc = mysql_connect('localhost','user','passwd');
    $sql = "select fieldx from database.dbtable where clause = 'somevalue'";
    $rs = mysql_query($sql);
    ?>
    <marquee width="200" scrollamount="10" scrolldelay="150"><?php echo mysql_result($rs,0,'fieldx');?></marquee>
    </body>
    </html>

  3. #3
    Join Date
    Dec 2009
    Posts
    20
    Thank you for your response. For those interested, after some more searching, I came up with the following. It uses jScroller2 for the scrolling effect (that way, I don't have to worry about the compatability of <marquee> plus I get more styling effects (speed mostly)).
    I've got the styling done in a css file. But this returns the list of Vendor names from the DB, and displays them in a random order (so each time someone visits the page, they don't see the same starting Vendors - there are currently over 240, so this way all vendors get displayed at some point).

    If anyone's got any suggestions for cleaning up any of the code, please let me know! Thanks!

    Code:
    <div id="vendorTicker">
    <?php
    mysql_connect(//CONNECTION INFO) or die(mysql_error());
    mysql_select_db(//DATABASE NAME) or die(mysql_error());
    
    $countquery = "SELECT COUNT(Name) FROM Vendors";
    $resultSet = mysql_query($countquery) or die(mysql_error());
    $row =  mysql_fetch_array($resultSet);
    $totalcount =  $row['COUNT(Name)'];
    
    $query = "SELECT Name FROM Vendors ORDER BY RAND() LIMIT " .$totalcount;
    $resultSet = mysql_query($query);
    ?>
    <div class="jscroller2_left jscroller2_speed-100 jscroller2_mousemove">
    <?php
    while($row = mysql_fetch_array($resultSet)) {
    ?>
    <div id="vendorDisplay">
    <?php print($row['Name']) ?>[/PHP]
    </div>
    <?php
    }
    mysql_close();
    ?>
    </div>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •