Forums Archive Index > Cool free scripts > Dynamic loading of newsticker content

Author: tex

Date: 4 Apr 2003 7:24 am

I maintain the news items in a database and would like to just write a file when they change and include that in the newsticker. I'm using ASP. What's the best way to do this kind of include?


Author: smartmenus

Date: 7 Apr 2003 8:34 pm

I think it's good enough to make the script .asp not .js and use an include for the v_content[]. Something like this:

v_content=[<!-- #INCLUDE FILE="array.asp" -->];

And the "array.asp" will pull the content from your database.


Author: Baka
Subject: And what about PHP?

Date: 21 May 2003 12:08 pm

How that would work in PHP? I needed the texts to be loaded dynamically, but I'm working with PHP, not ASP.

Thanks,

Charlie.


Author: smartmenus

Date: 22 May 2003 9:56 am

The same as for ASP. Only use .php for the script file and again you can use include for the v_content:

v_content=[<?php include ("array.php"); ?>];

And the "array.php" will pull the content from your database.


Author: vito33
Subject: passwd

Date: 11 Jun 2003 6:00 am

hello
Is it possible to include a .txt instead of an array. I don't know how to get an array from a database in ASP

Thank
Michel


Author: JPC
Subject: Dynamic data from ASP

Date: 10 Jul 2003 1:34 pm

I try the sample:

v_content=[<!-- #INCLUDE FILE="array.asp" -->];

But I always have an error about a missing bracket ]. :?

Did you have any idea ?

Thanks


Author: JPC
Subject: Oups!!

Date: 10 Jul 2003 1:36 pm

Here is my code:

Array.asp contain:
<%
response.write "['http://www.any.net/','<img src='img/red.gif' width=3 height=3> Good site','_blank']"
%>

And my page contain:
v_content=[<!--#INCLUDE FILE="array.asp"-->];


Author: MMax
Subject: Dynamic data from ASP

Date: 8 Sep 2003 8:17 am

I also have the same problem

about the missing bracket " ]. "

Can you give us a help?

Thanks&Rgds. :cry:


Author: smartmenus

Date: 8 Sep 2003 8:59 am

I will take a look and try to see what's wrong. I'm sorry that I have not seen the post earlier!


Author: Guest

Date: 23 Sep 2003 9:41 am

I have the same problem.
I tried ["", <!-- #include file="array.asp" -->,"" ] and it didn't work.


Author: smartmenus

Date: 24 Sep 2003 10:30 am

Hi,

I'm sorry once again for the delay but I am really very busy preparing SmartMenus 5.0 :(

I will try to answer tomorrow...

Thanks for the understanding!


Author: smartmenus

Date: 25 Sep 2003 6:32 am

Guys,

You all have a common problem because all of you don't succeed in sending correct syntax to the JavaScript engine of the browser. The correct syntax for the JavaScript is the following:

v_content=[
['link1','text1','target1'],
['link2','text2','target2'],
['link3','text3','target3']
];

Of course you can have any number of items. Only be sure that after the last ['linkX','textX','targetX'] you don't have a comma.

After you know the correct syntax that the JavaScript engine needs to work correctly, you can do any kind or type of include (using ASP, PHP...) and pull your content from the database, but you have to be sure that the "response.write", "echo", "printf" or any other method will format the output to JavaScript correctly and the browser will receive the code in the format I mentioned above. If you prefer, you can even not use an include and put all the code that pulls the content and formats it in the v_newsticker.asp(php...) but once again BE SURE to format correctly the output.

For instance JPC has the following code:

<%
response.write "['http://www.any.net/','<img src='img/red.gif' width=3 height=3> Good site','_blank']"
%>

At first sight everything looks fine and the array.asp should return good code. But look at the single quotes around the image's src attribute - src='img/red.gif' . Those quotes are breaking the array item's syntax and lead to the error he/she mentions. The correct syntax in this case is - src=\'img/red.gif\' . Or he/she can safely not use any quotes as the images's source url doesn't contain spaces and doesn't need quotes around it - src=img/red.gif .

So please be careful with the syntax ;) I know it's pretty confusing when you have to cope with the syntax of the server side script and the JavaScript code at the same time but there's no other way.

Cheers!

PS: Sorry for the delay once again!


Author: Orion
Subject: Help..........

Date: 30 Nov 2003 10:21 pm

Ok ive tired on my own but im not able to get it working.

What changes to the script do i have to make to get the headlines working from a .txt file?

Cheers,
Orion


Author: smartmenus

Date: 7 Dec 2003 6:46 am

You have to write a server-side script which will read the content of the text file and output it in the format required by the V-NewsTicker (an array).

Let's say you have formated your headlines in the .txt file this way:

headline1_link|headline1_text|headline1_target
headline2_link|headline2_text|headline2_target
...
headlineN_link|headlineN_text|headlineN_target

Your server-side script should parse this file and output

['headlineX_link','headlineX_text','headlineX_target']

for each new line of the .txt file.

I can write this script in PHP but unfortunately I don't have enough time :(

PS: I am sorry or the delay of my reply. I was pretty busy preparing v5.1.1


Author: The DareDevil

Date: 3 Feb 2004 11:58 am

It doesn't look like it likes any code at all. As soon as a bracket (<) is opened it generates an error.

ie. Code:
v_content=[<?php include ("array.php"); ?>];
doesn't work because of "<" (char 12).


Author: smartmenus

Date: 3 Feb 2004 2:16 pm

Are you sure your V-NewsTicker script file is actually a server-side script? Have you changed its extention from .js to .php?


Author: The DareDevil

Date: 3 Feb 2004 9:19 pm

smartmenus wrote:
Are you sure your V-NewsTicker script file is actually a server-side script? Have you changed its extention from .js to .php?I thought I had, but apparently that was not the case. I will change the extension and see what happens.

Thanks!