Create the javascript using PHP (see the comments in the code):
// suppose this is the rows array you get form the database
$rows = array(
array(
'sort' => 'sort1',
'url' => 'url1',
'details' => 'detail1',
'image' => 'image1'
),
array(
'sort' => 'sort2',
'url' => 'url2',
'details' => 'detail2',
'image' => 'image2'
),
array(
'sort' => 'sort3',
'url' => 'url3',
'details' => 'detail3',
'image' => 'image3'
),
);
// prepare a string for items array in javascript code
// you will use it below in $javascript
$items_string = '';
foreach($rows as $raw) {
// assign variables so everything is more readable
// you can also check for values of returned rows here
$sort = $raw['sort'];
$url = $raw['url'];
$details = $raw['details'];
$image = $raw['image'];
// compose th string
$items_string .= "items[$sort]=\"<a href='$url' target='_blank'>";
$items_string .= "<img alt='$details' src='$image' ";
$items_string .= "height='60' width='468' border='0'/></a>\";";
}
// compose javascript code using heredoc syntax
// see http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
$javascript = <<<JSCODE
<script type="text/javascript">
var howOften = 12;
var current = 0;
var ns6 = document.getElementById&&!document.all;
var items = new Array();
$items_string
function rotater() {
document.getElementById("placeholder").innerHTML = items[current];
current = (current==items.length-1) ? 0 : current + 1;
setTimeout("rotater()",howOften*1000);
}
function rotater() {
if(document.layers) {
document.placeholderlayer.document.write(items[current]);
document.placeholderlayer.document.close();
}
if(ns6)document.getElementById("placeholderdiv").innerHTML=items[current]
if(document.all)
placeholderdiv.innerHTML=items[current];
current = (current==items.length-1) ? 0 : current + 1;
setTimeout("rotater()",howOften*1000);
}
window.onload=rotater;
//-->
</script>
JSCODE;
// echo the javascript code on appropriate place in your html or php
echo $javascript;
If you do not like heredoc syntax you can compose …