And here is my javascript which is inside my html page
Code:
<script type="text/javascript">
var numofImages = "<?=$filecount?>";
var random_img = new Array();
for(var i=0;i<numofImages-1;i++) {
random_img[i] = '<a href="comics/'+i+'.png"><img src="comics/'+i+'.png"; width="260" height="320" border="0" alt=""></a>';
}
var random_number = Math.floor((Math.random()*random_img.length));
random_img[random_number];
document.write(random_img[random_number]);
</script>
Now, my problem is this, it wont get the file count. If I set numofImages to an actual number the entire thing works perfectly fine. But for some reason it doesn't seem to get the file count. Any tips?
Not knowing about your personal PHP/Javascript knowledge or how the page(s) are set up I'll first just toss in a little note to make sure that your script code itself is on a .php page and also obviously the same page that sets the $filecount variable.
Silly things out of the way, have you tried:
Code:
<script type="text/javascript">
var numofImages = "<?php echo $filecount; ?>";
var random_img = new Array();
for(var i=0;i<numofImages-1;i++) {
random_img[i] = '<a href="comics/'+i+'.png"><img src="comics/'+i+'.png"; width="260" height="320" border="0" alt=""></a>';
}
var random_number = Math.floor((Math.random()*random_img.length));
random_img[random_number];
document.write(random_img[random_number]);
</script>
I suppose I could have looked it up quickly, but I have never seen the format <?=$variable?> used to insert PHP in to a page. Generally I always set a proper opening and closing PHP tag and then simply echo out any data I want printed in the page's source.
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
Bookmarks