Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Question PHP Scrolling Marquee

    Hi All,

    Does anyone know how I can create a scrolling marquee that allows me to populate it with data from a database. I've seen alot of code that would create a scrolling marquee but doesnt allow for php.

    I also need it to pause on mouse over, allow links, and scroll from either left-right or right-left.

    This is the code i need it to contain:

    PHP Code:
    <?
    $a 
    mysql_query("SELECT * FROM jobs where status = '0' order by jobid desc limit 10");
    while(
    $b mysql_fetch_array($a))
    {
    ?>
    <tr>
    <td align="left" colspan="2"><b><a href=<?=$fullurl?>/info_jobid_<?=$b[jobid]?>.html><?=$b[position]?></a></b>
    <small>
    <br><b>Hours:</b> <?=$b[hour]?>
    <br><b>Job Location:</b>
    <?
    if(!empty($b[subcity]))
    {
    echo 
    "$b[subcity], $b[subcounty], $b[country]";
    }
    elseif(!empty(
    $b[subcounty]))
    {
    echo 
    "$b[subcounty], $b[country]";
    }
    else
    {
    echo 
    "$b[country]";
    }
    ?>
    <br>
    <b>Salary:</b> <?=$b[salary]?></small> 
    <hr style="background-color: rgb(204, 204, 204);" width="100%" size="1" noshade="noshade" color="#cccccc">
    </td>
    </tr>
    <?
    }
    ?>
    I would be grateful if someone could point me in the right direction.

    Thanks

  • #2
    Regular Coder
    Join Date
    Mar 2008
    Posts
    235
    Thanks
    6
    Thanked 21 Times in 20 Posts
    When you mean scrolling, do you mean similiar to where it says HOT NEWS on this link: http://www.apple.com/

    If so, you need a combination of PHP + Javascript to make it work. If you could elaborate with an example of what you've seen and liked would be great!

    Andrew Sharman
    Web designer, developer and programmer.

    If you found my post helpful, why not give thanks! :)

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by udjamaflip View Post
    When you mean scrolling, do you mean similiar to where it says HOT NEWS on this link: http://www.apple.com/
    Unfortunatley when i click the link i dont see anything that says hot news! I havnt really come across an example as such, but I'll have a look for one so that you can understand what i mean.

    Im talking about something like a tickertape, that you may see on news channels, that just scrolls across the bottom of the screen. Hope this helps to clear things up until i can find an example.
    Last edited by greens85; 05-22-2009 at 01:05 PM.

  • #4
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Well the ticker tape needs to be made in a client-side language, there are plenty of scripts about.
    Then each news item needs to be made by PHP, on the server, before the client receives the page.
    Let's assume you chose to use this example I found on dynamic drive:
    http://www.dynamicdrive.com/dynamicindex2/crosstick.htm
    Each item is made by this segment:
    Code:
    var pausecontent=new Array()
    pausecontent[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a><br />Comprehensive JavaScript tutorials and over 400+ free scripts!'
    pausecontent[1]='<a href="http://www.codingforums.com">Coding Forums</a><br />Web coding and development forums.'
    pausecontent[2]='<a href="http://www.cssdrive.com" target="_new">CSS Drive</a><br />Categorized CSS gallery and examples.'
    So you put your loop in the <head> section, with the JavaScript, a bit like this:
    PHP Code:
    pausecontent[0]='<?=$b[hour]?> '
    You can just embed the JS into the loop.
    Hope this helps.

  • #5
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Using another example from dynamic drive (as i want it to scroll horizontally).

    http://www.dynamicdrive.com/dynamici...ryscroller.htm

    Is there any way i could add php to this:

    Code:
    //Specify the scroller's content (don't delete <nobr> tag)
    //Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):
    
    var memorycontent='<nobr>Content is placed here</nobr>'
    Ive tried adding the PHP statement into this but it wont allow me to, is there a way round this?

    Sorry for my lack of knowledge Javascript/PHP is not my strong point!

  • #6
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    I've tried it with PHP just embedded into that statement, it works fine. Could you post your new code please?

  • #7
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Hi,

    This is what I tried, unfortunatley it didnt work for me!

    Code:
    var memorycontent='<nobr><?
    $a = mysql_query("SELECT * FROM jobs where status = '0' order by jobid desc limit 10");
    while($b = mysql_fetch_array($a))
    {
    ?>
    <tr>
    <td align="left" colspan="2"><b><a href=<?=$fullurl?>/info_jobid_<?=$b[jobid]?>.html><?=$b[position]?></a></b>
    <small>
    <br><b>Hours:</b> <?=$b[hour]?>
    <br><b>Job Location:</b>
    <?
    if(!empty($b[subcity]))
    {
    echo "$b[subcity], $b[subcounty], $b[country]";
    }
    elseif(!empty($b[subcounty]))
    {
    echo "$b[subcounty], $b[country]";
    }
    else
    {
    echo "$b[country]";
    }
    ?>
    <br>
    <b>Salary:</b> <?=$b[salary]?></small> 
    <hr style="background-color: rgb(204, 204, 204);" width="100%" size="1" noshade="noshade" color="#cccccc">
    </td>
    </tr>
    <?
    }
    ?></nobr>'
    Basically I just took the code that displays all the jobs in the database and dropped them inside the content var.

  • #8
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    OK,
    For a start, you've left some tables in at the bottom, and some general formatting things along the way, this will stop it from working.
    You really just need to remember that the PHP script will give the output to JavaScript, and that will try and display whatever it receives, we know both scripts work independently, you just have you make the output of PHP fit the required input:
    PHP Code:
    <?
    $a 
    mysql_query("SELECT * FROM jobs where status = '0' order by jobid desc limit 10");
    while(
    $b mysql_fetch_array($a))
    {
    ?>
    Hours: <?=$b[hour]?>
    Job Location:
    <?
    if(!empty($b[subcity]))
    {
    echo 
    "$b[subcity], $b[subcounty], $b[country]";
    }
    elseif(!empty(
    $b[subcounty]))
    {
    echo 
    "$b[subcounty], $b[country]";
    }
    else
    {
    echo 
    "$b[country]";
    }

    echo 
    "<b>Salary:</b>".$b[salary];
    }
    ?>

  • #9
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Ive tried it without the tables and with the formatting you pasted but still no look. I don't recieve an error but nothing is displayed when i load the page. Its like the code doesnt exist!

  • #10
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    OK, let's take this section by section, the code for hours is at the top, so start there.
    Take all the JS and PHP out of the body section, and put this in, tell me what happens:
    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Memory Scroller script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var memorywidth="300px" //scroller width
    var memoryheight="20px" //scroller height
    var memorybgcolor="#DEFDD9" //scroller background
    var memorypadding="2px" //padding applied to the scroller. 0 for non.
    var borderCSS="border: 1px solid black;" //Border CSS, applied to scroller to give border.
    
    var memoryspeed=2 //Scroller speed (larger is faster 1-10)
    var pauseit=1 //Pause scroller onMousever (0=no. 1=yes)?
    
    var persistlastviewedmsg=1 //should scroller's position persist after users navigate away (1=yes, 0=no)?
    var persistmsgbehavior="onload" //set to "onload" or "onclick".
    
    //Specify the scroller's content (don't delete <nobr> tag)
    //Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):
    
    var memorycontent='<nobr>
    <?php
    $a = mysql_query("SELECT * FROM jobs where status = '0' order by jobid desc limit 10");
    while($b = mysql_fetch_array($a))
    {
    echo $b['hour'];
    }
    php?>
    </nobr>'
    
    
    ////NO NEED TO EDIT BELOW THIS LINE////////////
    var combinedcssTable="width:"+(parseInt(memorywidth)+6)+"px;background-color:"+memorybgcolor+";padding:"+memorypadding+";"+borderCSS+";"
    var combinedcss="width:"+memorywidth+";height:"+memoryheight+";"
    
    var divonclick=(persistlastviewedmsg && persistmsgbehavior=="onclick")? 'onClick="savelastmsg()" ' : ''
    memoryspeed=(document.all)? memoryspeed : Math.max(1, memoryspeed-1) //slow speed down by 1 for NS
    var copyspeed=memoryspeed
    var pausespeed=(pauseit==0)? copyspeed: 0
    var iedom=document.all||document.getElementById
    if (iedom)
    document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-10000px">'+memorycontent+'</span>')
    var actualwidth=''
    var memoryscroller
    
    if (window.addEventListener)
    window.addEventListener("load", populatescroller, false)
    else if (window.attachEvent)
    window.attachEvent("onload", populatescroller)
    else if (document.all || document.getElementById)
    window.onload=populatescroller
    
    function populatescroller(){
    memoryscroller=document.getElementById? document.getElementById("memoryscroller") : document.all.memoryscroller
    memoryscroller.style.left=parseInt(memorywidth)+8+"px"
    if (persistlastviewedmsg && get_cookie("lastscrollerpos")!="")
    revivelastmsg()
    memoryscroller.innerHTML=memorycontent
    actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
    lefttime=setInterval("scrollmarquee()",20)
    }
    
    function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = ""
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) {
    offset += search.length
    end = document.cookie.indexOf(";", offset)
    if (end == -1)
    end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function savelastmsg(){
    document.cookie="lastscrollerpos="+memoryscroller.style.left
    }
    
    function revivelastmsg(){
    lastscrollerpos=parseInt(get_cookie("lastscrollerpos"))
    memoryscroller.style.left=parseInt(lastscrollerpos)+"px"
    }
    
    if (persistlastviewedmsg && persistmsgbehavior=="onload")
    window.onunload=savelastmsg
    
    function scrollmarquee(){
    if (parseInt(memoryscroller.style.left)>(actualwidth*(-1)+8))
    memoryscroller.style.left=parseInt(memoryscroller.style.left)-copyspeed+"px"
    else
    memoryscroller.style.left=parseInt(memorywidth)+8+"px"
    }
    
    if (iedom){
    with (document){
    document.write('<table border="0" cellspacing="0" cellpadding="0" style="'+combinedcssTable+'"><td>')
    write('<div style="position:relative;overflow:hidden;'+combinedcss+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=memoryspeed">')
    write('<div id="memoryscroller" style="position:absolute;left:0px;top:0px;" '+divonclick+'></div>')
    write('</div>')
    document.write('</td></table>')
    }
    }
    </script>

  • #11
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Same result as before

    Seems that any php placed between the var memorycontent='<nobr></nobr>' doesnt display.

  • #12
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Well try it with:
    PHP Code:
    <?php echo "test"?>
    That worked fine for me with the marquee.
    I think you might have something wrong with your query and loop. Did that work before you posted?
    Could you take the database password out and post the whole file?

  • #13
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    It works with the following:

    Code:
    var memorycontent='<nobr><?php echo 'test' ?></nobr>'
    The whole script is huge, I can still post it if you like, but its like 307 lines long

  • #14
    New Coder
    Join Date
    May 2009
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    OK well I set up a dummy database which I think is fairly similar to yours. Let's look at the query, I think it might not actually be selecting any data. Could you change it to this:
    PHP Code:
    $a mysql_query("SELECT * FROM jobs"); 

  • #15
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Obviously you know PHP much better than I do, but i know for certain that the query is selecting the data. Ive had a previous scroller, but it was a vertical one. It selected the data in the same way and was fine.

    If it helps the code for that scroller is:

    Code:
    <table width="90%" border="0" cellspacing="0" cellpadding="5">
    <tr>
    <td align="left" class="tcat">Latest Education Jobs</td>
    </tr>
    <td align='left' style='border:1px solid #cccccc'">
    <style type="text/css">
    #marqueecontainer{
    position: relative;
    width: 100%; /*marquee width */
    height: 300px; /*marquee height */
    background-color: white;
    overflow: hidden;
    border: 0px solid orange;
    padding: 2px;
    padding-left: 2px;
    background-color:#FFFFFF;
    }
    </style>
    
    <script type="text/javascript">
    var delayb4scroll=2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
    var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
    var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?
    
    ////NO NEED TO EDIT BELOW THIS LINE////////////
    
    var copyspeed=marqueespeed
    var pausespeed=(pauseit==0)? copyspeed: 0
    var actualheight=''
    
    function scrollmarquee(){
    if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
    cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
    else
    cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
    }
    
    function initializemarquee(){
    cross_marquee=document.getElementById("vmarquee")
    cross_marquee.style.top=0
    marqueeheight=document.getElementById("marqueecontainer").offsetHeight
    actualheight=cross_marquee.offsetHeight
    if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
    cross_marquee.style.height=marqueeheight+"px"
    cross_marquee.style.overflow="scroll"
    return
    }
    setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
    }
    
    if (window.addEventListener)
    window.addEventListener("load", initializemarquee, false)
    else if (window.attachEvent)
    window.attachEvent("onload", initializemarquee)
    else if (document.getElementById)
    window.onload=initializemarquee
    
    </script>
    <div id="marqueecontainer" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">
    <div id="vmarquee" style="position:relative; width: 99%;">
        
    <table width="100%"  border="0" cellspacing="0" cellpadding="2">
    <?
    $a = mysql_query("SELECT * FROM jobs where status = '0' order by jobid desc limit 10");
    while($b = mysql_fetch_array($a))
    {
    ?>
    <tr>
    <td align="left" colspan="2"><b><a href=<?=$fullurl?>/info_jobid_<?=$b[jobid]?>.html><?=$b[position]?></a></b>
    <small>
    <br><b>Hours:</b> <?=$b[hour]?>
    <br><b>Job Location:</b>
    <?
    if(!empty($b[subcity]))
    {
    echo "$b[subcity], $b[subcounty], $b[country]";
    }
    elseif(!empty($b[subcounty]))
    {
    echo "$b[subcounty], $b[country]";
    }
    else
    {
    echo "$b[country]";
    }
    ?>
    <br>
    <b>Salary:</b> <?=$b[salary]?></small> 
    <hr style="background-color: rgb(204, 204, 204);" width="100%" size="1" noshade="noshade" color="#cccccc">
    </td>
    </tr>
    <?
    }
    ?>
    </table>
    </div>
    </div>
    <hr style="background-color: rgb(204, 204, 204);" width="100%" size="1" noshade="noshade" color="#cccccc">
    <div><a href="<?=$fullurl?>/rss.php" title="RSS Feeds"><img src="<?=$fullurl?>/images/rss1.gif"  border="0" /></a> 
    <a href='javascript:void(0);' onclick="open_win()">What is RSS?</a></div>
    </table>
    I inherited this code, so ive no idea how it works or anything like that


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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