Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

News ticker that pulls info from db 1

Status
Not open for further replies.

katherinep

Programmer
Sep 18, 2003
49
AU
Hello,

I would like a news ticker on my site that moves horizontally across the screen and pulls the information from my database, I would like it to contain hyperlinks so people can click on a headline and then get a page with the full article.

I found a ticker I like from


and I also know how to pull information from a database using asp. I am having trouble bringing the two together.

I can get the ticker to show one record and hyperlink on a page:

var marqueecontent='<nobr><font face="Arial"> <a href="event.asp"> <%= rstGetResults("Headline")%> - <%= rstGetResults("Date")%></font></nobr>'


But as soon as I try and make it loop to show all records or hyperlink to a page and pass a parameter (the id of the record to display i.e. <a href="event.asp?nid=<%= rstGetResults("id")%>"> ) I get a blank page.

Can anyone point me in the right direction, I have tickers in ColdFusion, but I can't seem to get one to work in ASP,

My table is called 'news' and my fields are called Id, Date and Headline, my database is in Microsoft Access.

Thanks in Advance,

Katherine
 
You will need to add some more javascript since your data is on the server. The easiest way to handle this would probably be to either add all the data to the marquee in the beginning or to create an array of entries and add more javascript to change the marquee occasionally.
I'll admit I am a little confused as to why your using that large chunk of javascript to do something that could easily be done with a marquee tag, but hey, up to you.

If you add all the data to the marquee your going to need to build a string of all the inner html then assign it in one go, kinda like:
Code:
Dim marqText
Do Until rstGetResults.EOF
   marqText = marqText & "<a href=""event.asp"">" &  rstGetResults("Headline") & " - " & rstGetResults("Date") & "</a>"
   rstGetResults.MoveNext
Loop
%>
var marqueecontent='<nobr><%=Replace(marqText,"'","\'")%></nobr>';

I would probably want to add some style to add some margins to those anchor tags, but that would print out everything into the marquee for you.

Like I said the other method would be to drop the data into an array then add some code to occasionally change the content in the marquee, but that would be even more in depth and probably not give you much more functionality.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
Here's some code that works in a marquee. Obviously it will need to be tweaked to work on your site, but it is a good framework.
Code:
<%
				
	Set rstCurrent = Server.CreateObject("ADODB.Recordset")
	rstCurrent.activeconnection= (your connection string)
	rstCurrent.source = "SELECT * FROM items ORDER BY itemID DESC"
	
	rstCurrent.Open

	sHtml1 = "<FONT SIZE='-1' COLOR='Black'>"
	sHtml2 = "<A HREF='itemdetail.asp?itemID="
	sHtml3 = "'>"
	sHtml4 = "</A></FONT>&nbsp;&nbsp;::&nbsp;&nbsp;"
	sTxt = ""
	rstCurrent.movefirst
	do while not rstCurrent.eof	'variables used to make it easier to read
		sTxt = sTxt & sHtml1 & sHtml2 & _
		 rstCurrent("itemID") & sHtml3 & rstCurrent("itemTitle") & sHtml4
		rstCurrent.movenext
	loop
	
	iSpeed =0 	' Speed of Marquee (higher = slower)
   	iTop = 0		' Y Location Within Object
   	iLeft = 0		' X Location""""
   	iWidth = "100%" ' Width 
   	iHeight = 20	' Height
   	'Insert marquee into objects innerHtml Property (in this Case a table cell)
	sMarquee="<MARQUEE onmouseover='this.stop();' " & _
	 "onmouseout='this.start();'direction='left' scrollamount='4' " & _
	 "scrolldelay='" & iSpeed & "' top='" & iTop & "' left='" & iLeft & _
	 "' width='" & iWidth & "' height='" & iHeight & "'>" & sTxt & "</MARQUEE>"
 
    %>

then just <%=sMarquee%> where you want it to appear on the page.

Steve Davis
hey.you AT HaHaHa.com.au

Me? I can't even spell ASP!

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination
 
Thanks for all the help, and thanks Microbe I think I was making life way too difficult for myself and your code works perfectly!
 
Microbe..great code.
However, how can I add image object as well... there is only text objects.

please advice.


=============================CODE=========================
<%

Set rstCurrent = Server.CreateObject("ADODB.Recordset")
rstCurrent.activeconnection= ("DRIVER={SQL Server};SERVER=server;DATABASE=XX;UID=user;PWD=password")
rstCurrent.source = "SELECT * FROM MarqueeTop"

rstCurrent.Open

sHtml1 = "<FONT SIZE='2' family='Arial' color='#4A7194'>"
sHtml2 = "<A HREF='itemdetail.asp?ItemID="
sHtml3 = "'>"
sHtml4 = "</A></FONT>&nbsp;&nbsp;::&nbsp;&nbsp;"
sTxt = ""
rstCurrent.movefirst
do while not rstCurrent.eof 'variables used to make it easier to read
sTxt = sTxt & sHtml1 & sHtml2 & _
rstCurrent("itemID") & sHtml3 & rstCurrent("SmallImgPath") & rstCurrent("ItemDesc") & sHtml4
rstCurrent.movenext
loop

iSpeed = 20 ' Speed of Marquee (higher = slower)
iTop = 0 ' Y Location Within Object
iLeft = 0 ' X Location""""
iWidth = "100%" ' Width
iHeight = 30 ' Height
'Insert marquee into objects innerHtml Property (in this Case a table cell)
sMarquee="<MARQUEE onmouseover='this.stop();' " & _
"onmouseout='this.start();'direction='left' scrollamount='1' " & _
"scrolldelay='" & iSpeed & "' top='" & iTop & "' left='" & iLeft & _
"' width='" & iWidth & "' height='" & iHeight & "'>" & sTxt & "</MARQUEE>"

%>
========================================================
 
Since it is a scrolling text banner, you can't add image object to it.

For the record, I dodn't write the code, can't even remember where I got it, but I think I did hack it a bit to get it to do what i wanted.

Steve Davis
ttf(a)HaHaHa.com.au

Me? I can't even spell ASP!

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top