Ciao.
Se capito bene questo potrebbe
esserti utile:
Come vedi lo snippet fa anche dell'altroCodice PHP:<?php
$db=mysql_connect('localhost','','') or die('Error connecting to the server');
mysql_select_db('blogial') or die('Error selecting database');
$result=mysql_query('SELECT cat_name FROM categories') or die ('Error performing query');
function createJavaScript($dataSource,$arrayName='rows'){
// validate variable name
if(!is_string($arrayName)){
die('Invalid variable name');
}
// initialize JavaScript string
$javascript='<script>var '.$arrayName.'=[];';
// check if $dataSource is a file or a result set
if(is_file($dataSource)){
// read data from file
$row=file($dataSource);
// build JavaScript array
for($i=0;$i<count($row);$i++){
$javascript.=$arrayName.'['.$i.']="'.trim($row[$i]).'";';
$javascript.="\n";
}
}
// read data from result set
else
{
$i = 0;
$tempOutput='';
while($row=mysql_fetch_array($dataSource,MYSQL_NUM))
{
$tempOutput.= $arrayName.'['.$i.']'."=\"".trim($row[0]).'";';
$tempOutput.= "\n";
$i++;
}
$javascript.= $tempOutput;
}
$javascript.='</script>'."\n";
// return JavaScript code
return $javascript;
}
echo createJavaScript('news.txt','news');
?>
<html>
<head>
<title>CLIENT-SIDE NEWS TICKER</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script language="javascript">
var numNews,counter;
// count number of news
numNews=news.length;
// initialize news counter
counter=0;
createNewsDiv=function(){
// create news containing <div> element
var newsDiv=document.createElement('div');
newsDiv.id='news';
// insert news <div> into document structure
//document.body.appendChild(newsDiv);
document.getElementById('po').appendChild(newsDiv);
}
rotateNews=function(){
// get news containing <div>
var newsDiv=document.getElementById('news');
if(!newsDiv){return;}
// create new <div> element
var div=document.createElement('div');
div.id='news';
// create paragraph for each news line
var p=document.createElement('p');
// style
element
p.style.fontFamily='Verdana';
p.style.fontSize='11px';
p.style.fontWeight='bold';
p.style.color='#c00';
if(counter==numNews){counter=0;}
p.appendChild(document.createTextNode(news[counter]));
// insert paragraph into <div> news
div.appendChild(p);
// replace old <div> node with new <div> node
newsDiv.parentNode.replaceChild(div,newsDiv);
counter++;
// rotate news every 10 seconds
setTimeout('rotateNews()',1*1000);
}
timing = function()
{
//setTimeout('rotateNews()',1*1000);
}
// execute functions when page is loaded
window.onload=function(){
if(document.getElementById){
createNewsDiv();
rotateNews();
}
}
</script>
<style type="text/css">
/*define style for news container*/
#news {
background: #eee;
padding: 2px 0px 2px 10px;
border: 1px solid #000;
}
</style>
</head>
<body>
<div id="po"></div>
</body>
</html>
ma penso che per darti lo spunto possa
andare.
![]()


Rispondi quotando