Hey all,
I have some javascript on the main page of my website that changes the news image and header every 7 seconds in a <div>. I have it set up working fine but I dont want to be able to just update my database as opposed to having to update the code everytime the news changes. Whats the easiest way to set Javascript variables with PHP?
I know AJAX deals with PHP and JS interaction but I have never played with that before. Any pointers? Preferably something simple that wont slow down the loading of the page too much (I guess thats always the idea though :P)
Thanks
EDIT:
Actually I just answered my own question. Because I am just setting variables and not running anything I just add the PHP code into the JS where I want it.
PHP Code:
<script type="text/javascript">
var bigTitle = new Array();
bigTitle[1]="<?php echo $firsttitle; ?>";
bigTitle[2]="<?php echo $secondtitle; ?>";
</script>
I just put this in the body of the page and then call the JS function in the head. By doing this I can query the database with PHP right before the code I just pasted in order to set the varialbes.
Hopefully this helps someone else too.
__________________
DVD Movie Release Database: Please login or register to view this content. Registration is FREE
Last edited by Truly; 11-27-2008 at 11:18 PM..
|