SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    scrolling Javascript & php help?

    Hi Guys,

    Iím using a vertical scrolling Javascript, and I want to embed the following php into it:

    PHP Code:
    <?
    // select all records ordered by date
    $SQL "Select * FROM `cms_hot_jobs`";

    // make the query (assume connection is there)
    $result mysql_query($SQL) OR die(mysql_error());

    // iterate the result set
    while ($row mysql_fetch_assoc($result)){
    echo 
    "".stripslashes($row['title'])."<br />";
    echo 
    "".stripslashes($row['organisation'])."<br />";
    echo 
    '<a class="more" onclick="WinOpenJob('.$row['job_id'].')")  href="javascript:void(0)">[ More ]</a>';
    echo 
    "<br /><br />";
    }
    ?>
    However, if I just copy and paste the php in the var scrollercontent below it simply outputs a javascript error. Can this work by using this php statement in the below javascript code?

    Thanks

    Chris

    HTML Code:
    <table width="185" height="450" border="2" cellpadding="0" cellspacing="0" bordercolor="#666666">
      <tr>
        <td><script language="JavaScript1.2">
    	
    // Distributed by http://www.hypergurl.com // Scrollers width here (in pixels) 
    
    var scrollerwidth="185px"
    
    var scrollerheight="450px"
    
    var scrollerspeed=1
    
    var scrollercontent='This is where I want the php to go'
    
    var pauseit=3
    
    scrollerspeed=(document.all)? scrollerspeed : Math.max(1, scrollerspeed-1)
    var copyspeed=scrollerspeed
    var iedom=document.all||document.getElementById
    var actualheight=''
    var cross_scroller, ns_scroller
    var pausespeed=(pauseit==0)? copyspeed: 0
    
    function populate(){
    if (iedom){
    cross_scroller=document.getElementById? document.getElementById("iescroller") : document.all.iescroller
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    cross_scroller.innerHTML=scrollercontent
    actualheight=cross_scroller.offsetHeight
    }
    else if (document.layers){
    ns_scroller=document.ns_scroller.document.ns_scroller2
    ns_scroller.top=parseInt(scrollerheight)+8
    ns_scroller.document.write(scrollercontent)
    ns_scroller.document.close()
    actualheight=ns_scroller.document.height
    }
    lefttime=setInterval("scrollscroller()",20)
    }
    window.onload=populate
    
    function scrollscroller(){
    
    if (iedom){
    if (parseInt(cross_scroller.style.top)>(actualheight*(-1)+8))
    cross_scroller.style.top=parseInt(cross_scroller.style.top)-copyspeed+"px"
    else
    cross_scroller.style.top=parseInt(scrollerheight)+8+"px"
    }
    else if (document.layers){
    if (ns_scroller.top>(actualheight*(-1)+8))
    ns_scroller.top-=copyspeed
    else
    ns_scroller.top=parseInt(scrollerheight)+8
    }
    }
    
    if (iedom||document.layers){
    with (document){
    if (iedom){
    write('<div style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed">')
    write('<div id="iescroller" style="position:absolute;left:0px;top:0px;width:100%;">')
    write('</div></div>')
    }
    else if (document.layers){
    write('<ilayer width='+scrollerwidth+' height='+scrollerheight+' name="ns_scroller">')
    write('<layer name="ns_scroller2" width='+scrollerwidth+' height='+scrollerheight+' left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=scrollerspeed"></layer>')
    write('</ilayer>')
    }
    }
    }
    
    </script></td>
      </tr>
    
    </table>
    </body>
    </html>

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ignoring the fact that that javascript is absolutely hideous, you have to check that the stuff echoed by the PHP doesn't contain any unescaped single quotes. What the error is would be helpful, as would be to see the javascript after PHP has processed it.

  3. #3
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, escaping single quotes - I understand now!

    Got it all working apart from this line:

    PHP Code:
    echo \'<a class="more" onclick="WinOpenJob(\'.$row['job_id'].\')")  href="javascript:void(0)">[ More ]</a>\'; 
    Have I not escaped properly?

    Also another quick question, I know the JS is not great as you said, but what I'm looking for is something like this:

    http://www.hypergurl.com/verticaltext.html

    Anyone suggest any better Javascripts that have this effect?

    Thanks

    Chris

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't need to escape any of the single quotes on that line. You also have two closing brackets, so you need to get rid of the last one.

    I don't know, but that javascript is clearly very old. It's catering for browsers that understand <ilayer> (old Netscape), it's using the "language" attribute instead of type="text/javascript" and it uses document.write in javascript that's just been dumped in the middle of the HTML. This is the sort of javascript that should sit in an external file and, when the page loads, it targets a specific <p> or <div> with the content, probably with getElementById. Then using just that information, it sets it to scroll.

    In any case, I don't like things that move about on the screen so I've never had any interest in this sort of stuff. Maybe by looking at the code (it's fairly simple) you can write your own unobtrusive solution.

  5. #5
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the explanation! I'll look into this ;-)


Bookmarks

Posting Permissions

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