newbie question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
hi, i'm new to this newsgroup and php/web development in general.  
there's something seemingly simple i'm trying to accomplish, but i'm  
having trouble predicting the behavior of php, particularly having it  
interface with javascript, which i am required to use to some extent.

basically i have a java applet embedded in the page which receives  
commands via javascript. the purpose of this applet is to perform a sort  
of multi-frame animation. there is a file on the server which in each  
line contains the file to be loaded next in the animation. so, what i  
would like is to have a button (which functionally should load the next  
frame, i'll call it '>') that, when clicked, calls a php function to  
read the next line from the file on the server, parse it, and feed that  
information into a javascript function call.

so: do i want to make php call a javascript function every time this  
button is clicked (something i've had trouble getting to work), or, is  
it possible to call a php function that reads the file and returns the  
information? or is there something else i'm missing?

thanks in advance for any help.

Re: newbie question

eruhk wrote:

Quoted text here. Click to load it

Java, Javascript, and PHP. Funky setup you have. :-)

Quoted text here. Click to load it

No, PHP is executed on request-basis.
That means that something (an applet, or Javascript, or a user pressing a  
hyperlink) has to call the PHP-page.
PHP itself will execute, produce some response (possible containing  
javascript) and ends. PHP cannot call a Javascriptfunction in some  
HTML-page directly.

or, is
Quoted text here. Click to load it

That is easy.
Go to and search for (using the searchoption and select  
'functions') functions like fopen() and file().

If you need to remember which line to send, also learn how to pass  
information to a PHP-script from a request.
the following hyperlink:

sends to myPHP.php a name/value pair. Name=counter and its value is 5. You  
can retrieve that from inside you PHP script using $_GET["count"]

 or is there something else i'm missing?
Quoted text here. Click to load it

Hard to say. :-)

Quoted text here. Click to load it

Good luck.

Erwin Moller

Re: newbie question

What you should do is have PHP create the page that contains your
Javascript and applet.  Have it load all of the file names from the
text file and store them in a Javascript array.  That way you don't
have to reload your page each time you need the next file name.  Here
is an example of what the code might look like:

echo "html and javascript header tags go here";
echo "var imageFiles=new Array()";
//load the file into a Javascript array
$fp = fopen("file.dat", "r");
while (!feof($fp)) {
  $lineContent = fgets ($fp, 4096);
  echo "imageFiles.push = ('$lineContent')";
echo "The rest of your javascript and html code goes here";

Thats about it, let me know how it goes.

Jon Tjemsland

Site Timeline