Web Hosting Talk







View Full Version : "videprinter" style news headline query


Davey Gale
09-20-2005, 09:27 AM
Hi there

For a site i'd like to have the latest news headline get typed out onto the page letter for letter (one by one) in the style of a teleprinter, or videprinter.

I've found lots of javascript examples which do this where you enter the text into the script and use that.

But i'd like mine to be dynamic. So, imagine there's about 5 news stories with headlines in a mySQL database, i'd want the script to pull out the headline of the top story and type it out across the screen in the desired way.

I ask for it to be dynamic as the person it's for would be updating their own news stories directly into the database. I wouldnt want them to have to keep entering new stories into the javascript code directly - as they wont have access to it.

Anyone got a script for this effect - or a tutorial? Any help or leads would be most appreciated. Thanks in advance!

Davey Gale
09-21-2005, 06:48 AM
I've tried this code below but this types out each news headline one after the other across the page, and the headline itself isnt a dynamic link - so it cant go through to the main news story. Can anyone help?

I really need this code to type out a news headline, then disappear and have the 2nd news headline type out in its place, and the 3rd and so on, in a loop through all present stories in the db. Each time any headline appears, it needs to be clickable through to the relating news story.

(basically have a db with a headline field, and a story field. just need this code to type out the headlines in a loop and have it clickable, to go through to page where the story is).


<script language="JavaScript1.2">

var it=0
function initialize(){
mytext=typing.innerText
var myheight=typing.offsetHeight
typing.innerText=''
document.all.typing.style.height=myheight
document.all.typing.style.visibility="visible"
typeit()
}
function typeit(){
typing.insertAdjacentText("beforeEnd",mytext.charAt(it))
if (it<mytext.length-1){
it++
setTimeout("typeit()",100)
}
else
return
}
if (document.all)
document.body.onload=initialize
</script>

<small><span id="typing" style="visibility:hidden" align="left"><?
// includes
include("config.php");
include("functions.php");

// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");

// select database
mysql_select_db($db) or die ("Unable to select database!");

// generate and execute query
$query = "SELECT id, title, timestamp FROM news ORDER BY timestamp DESC LIMIT 0, 5";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());

// if records present
if (mysql_num_rows($result) > 0)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?><a href="news.php?id=<? echo $row->id; ?>">
<? echo $row->title; ?>
</a><?
}
}
// if no records present
// display message
else
{
?>
<font class="news">No news currently available</font>
<?
}

// close database connection
mysql_close($connection);
?></span></small>

PlanetWebHost
09-21-2005, 08:32 AM
looks like your on the right track.
if you could link to where it's running we'll take a look and maybe see better where your having your problem.

Davey Gale
09-21-2005, 09:05 AM
http://www.readingnightlife.co.uk/scroller.php

That is the link. I must add that the news story is not iterating through each story headline, just doing it one after the other.

Also, it's just text, no link is working.

Any feedback would be great - it's a real puzzler! :)

Davey Gale
09-21-2005, 09:08 AM
And the database is simply:

id
headline
story

two text fields, and a smallint for the id.

I'm sorting the output of headlines by id number. Would like to add a timestamp field to sort by that when i can get it working.

Davey Gale
09-21-2005, 10:46 AM
Correction, the fields are:

id
title
story
timestamp

(i didnt realise my colleague had added these fields - dont s'pose it matters)

Any feedback anyone? Has anyone checked out the link to see what i mean?

Davey Gale
09-22-2005, 04:20 AM
Just bumping this back up - really scratching my head over this. :)