View Full Version : Advanced RSS Ticker (Ajax invocation)

06-11-2007, 05:31 PM
1) Script Title: Advanced RSS Ticker (Ajax invocation)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/rsstickerajax/index.htm

3) Describe problem: Script works fine, but is there a way to pass variables into the rss url in bridge.php? I want the news to be dynamic, so that when the user chooses a topic, the topic variable will be placed in bridge.php and the RSS ticker will display news from that topic.

Ex. The general news will be computers. If the user chooses Macs from the drop down, that keyword gets passed to bridge.php and sent back to the ticker which will display Mac computer news.

The variables are being passed to a database and i want to retrieve them in bridge. I have tried a couple of ways and I get non object errors.

Can anyone please offer me some ideas? Thank you.

06-12-2007, 11:10 AM
It's certainly possible, though what can make it complicated arae the finer details of what you're trying to do. In general, you can get the script to change feeds midway by:

1) Add the below new function to the end of the rsspauseticker.js:

// -------------------------------------------------------------------
// do_updatefeed()- Updates a ticker with a new feed
// -------------------------------------------------------------------

var parameters="id="+encodeURIComponent(RSS_id)+"&divid="+this.tickerid+"&bustcache="+new Date().getTime()


2) With the new function installed, you can get a ticker to change feeds via a link this way:

<script type="text/javascript">
var cnnstuff=new rsspausescroller("cnn", "pscroller1", "rssclass", 3000, "_new")

<!--update feed to that with RSS_id="dynamicdrive"-->
<a href='javascript:cnnstuff.updatefeed("dynamicdrive")'>test</a>

The code in red highlights what's new relative to your old code. Basically, you define an arbitrary variable "cnnstuff" to reference this particular ticker instance, then inside a link or elsewhere, call "cnnstuff.updatefeed()" to update its feed.

This is the basic idea. Obviously you'll have to take it a step further based on what you described you're trying to do.

06-12-2007, 05:28 PM
Here is my array

// List of RSS URLs
"CNN" => "http://rss.cnn.com/rss/cnn_topstories.rss",
"BBC" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",
"news.com" => "http://news.com.com/2547-1_3-0-5.xml",
"slashdot" => "http://rss.slashdot.org/Slashdot/slashdot",
"dynamicdrive" => "http://www.dynamicdrive.com/export.php?type=new",
"grk" => "http://news.search.yahoo.com/news/rss?p=fraternity+OR+sorority+AND+greek+AND+<?=$greek1?>%20<?=$greek2?>%20<?=$greek3?>&ei=UTF-8&fl=0&x=wrt|max=30|title=none"

Focus on grk.

Is it possible to pass the variables needed for <?=$greek1?>, <?=$greek2?> and <?=$greek3?>, by querying the database in bridge.php and populating the variables?

Whenever I tried to add additional php code into bridge.php, i received errors. Should I do an include instead or will I just get the same errors again?

06-14-2007, 03:42 PM
This really is a general question on PHP then. You asked about embedding the variables $greek in such a manner:

"grk" => "http://news.search.yahoo.com/news/rss?p=fraternity+OR+sorority+AND+greek+AND+<?=$greek1?>&#37;20<?=$greek2?>%20<?=$greek3?>&ei=UTF-8&fl=0&x=wrt|max=30|title=none"

which doesn't work because the syntax:


is invalid in such a setting. You only use <? ?> when you're outputting the contents of a PHP variable onto the page, not when you wish to use it within some PHP statement to construct a different variable. In the later case, you use the dot (append) syntax, for example:

$john= 'John is ' . $greek1;

06-15-2007, 09:16 PM
ok, that was my mistake. I wasnt really paying attention to what I was doing. I forgot that it was in an array and inside the php brackets. This is what I have - "grk" => "http://news.search.yahoo.com/news/rss?p=fraternity+OR+sorority+AND+greek+AND+" . $greek1 . "%20" . $greek2. "%20" . $greek3 . "&ei=UTF-8&fl=0&x=wrt|max=30|title=none"

I still have a problem getting it to work, but now I think its more to do with the address being processed before the main pages gets to add the variables to it. I connected to the database and initialized my variables on the main page, so when the ticker comes up, I dont think it accepts the values of the variables.