PDA

View Full Version : PHP to javacript


lazer
10-21-2002, 11:37 AM
I dont know if this has been up in the forum.

I am currently building a picture gallery.
And I am searching a directory and listing all files it found in an array named phparray.


With this array I must somehow use it to view the pictures it found, and this must be done with javascripts.

I am using the echo function to return phparray[nr]
but this number (nr-) wont count up, I have tried to do the counter with javascripts, and with php but it wont count up.

my currently count function is:
$nr=$nr+1

but somehow this wont work.
Is there some other way to do it?

beetle
10-21-2002, 04:17 PM
We'll need to see more code than that to help out...

are you using $nr as a javascript variable? I know that the $ is required for PHP, but should not be used for JS.

lazer
10-21-2002, 11:52 PM
Well, I've found a sulotion with this code at least:

<? for($nr2=0; $nr2<count($phparray); $nr2++) { ?>
bildarray[<?=$nr2;?>] = new Image;
bildarray[<?=$nr2;?>].src = "<?=$phparray[$nr2];?>";
<? } ?>

mordred
10-22-2002, 02:23 PM
OT: Better change your code above,

<?

will only work if short_open_tag is enabled, and this option must be disabled to work with XML/XHTML files. In such a case your code above would fail, you should better use

<?php

and drop the shorthand <?= statements. Your code is so short that you just have to print the values as a string instead of dropping out of PHP parsing mode again and again.