Jump to content

Scrolling php loops


nick_L

Recommended Posts

Hi I need to make a ticker of the stock quotes for my web design class, so far we got the variable to display but we can't get the text to scroll.

 

Here is an example without javascript: http://script.webpageexpress.net/ticker.php

 

Here is a fail atempt using liscroll :http://nicklegotte.net/ticker.php

 

Here is the full code

 

 

<html>
<head><script type=text/javascript>
// The time out value is set to be 10,000 milli-seconds (or 10 seconds)
setTimeout(' document.location=document.location' ,10000);
</script>
<script type="text/javascript">    
/*!
* liScroll 1.0
* Examples and documentation at: 
* http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
* 2007-2009 Gian Carlo Mingati
* Version: 1.0.1 (07-DECEMBER-2009)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
* Requires:
* jQuery v1.2.x or later
* 
*/


jQuery.fn.liScroll = function(settings) {
	settings = jQuery.extend({
	travelocity: 0.07
	}, settings);		
	return this.each(function(){
			var $strip = jQuery(this);
			$strip.addClass("newsticker")
			var stripWidth = 0;
			var $mask = $strip.wrap("<div class='mask'></div>");
			var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");								
			var containerWidth = $strip.parent().parent().width();	//a.k.a. 'mask' width 	
			$strip.find("li").each(function(i){
			stripWidth += jQuery(this, i).width();
			});
			$strip.width(stripWidth);			
			var totalTravel = stripWidth+containerWidth;
			var defTiming = totalTravel/settings.travelocity;	// thanks to Scott Waye		
			function scrollnews(spazio, tempo){
			$strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
			}
			scrollnews(totalTravel, defTiming);				
			$strip.hover(function(){
			jQuery(this).stop();
			},
			function(){
			var offset = jQuery(this).offset();
			var residualSpace = offset.left + stripWidth;
			var residualTime = residualSpace/settings.travelocity;
			scrollnews(residualSpace, residualTime);
			});			
	});	
};
</script>
<link href="/untitled.css" rel="stylesheet" type="text/css">
</head>
<body>

<?php

error_reporting(0);
class getStock {
function getQuote($stock) {
	$url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1c1p2&e=.csv", $stock);
	$fp  = @fopen($url, 'r');
	$data = @fgetcsv($fp, 1000, ', '); 
	fclose($fp);
	$this->symbol = $data[0];
	$this->price = number_format($data[1],2);
	$this->change = number_format($data[2],2);
$this->percent = number_format($data[3],1);
}
}

$stocks = array('^DJI','GOOG','YHOO','F');
$count = 0;
$quote = new getStock;

?>
<?php
echo 'STOCK QUOTES';

foreach ($stocks as $stock) {
    $quote->getQuote($stocks[$count++]);
    echo '<ul id="ticker01">'.$quote->symbol.'</td>'."\n";
    echo '<li><span>$' .$quote->price. ','."</li></span>";
    echo '<li><span>';
    if ($quote->change > 0) {
        echo 'color:#006600;">+' .      $quote->change. ', +' .$quote->percent. '%';
    } elseif ($quote->change < 0) {
        echo 'color:#a32900;">' .       $quote->change. ', -' .$quote->percent. '%';
    } else {
        echo 'font-size:100%;">' .      $quote->change. ', ' .$quote->percent. '%';
    }
    echo '</span></td></li>'."\n";
}

?>




<script type="text/javascript">
$(function(){ 
    $("ul#ticker01").liScroll(); 
}); 
</script>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.