[FX.php List] PHP and Javascript?

Michael Layne fx at 9degrees.com
Thu Sep 7 21:05:33 MDT 2006


Chuck,

Well, here's how I populate a JavaScript array with a PHP one... 
grabbing photos that live in the file system and belong to a particular 
record ($record)

<script type="text/javascript" language="javascript">
<?
$maindir = $_SERVER['DOCUMENT_ROOT']."/" . $site . "/photos/";
$mydir = opendir($maindir) ;
$c = 0;
while($fn = readdir($mydir)) {
    if ($fn!= "." && $fn!= ".." && substr($fn, 0, 5) == $record) {  
//this condition can be anything or nothing.  It's specific to my app...
    echo "Pic[" . substr($c,0,2) . "] = '../photos/" . $fn . "';\n"; // 
here's where the JavaScript array gets outputted.
    $c++;
    }
}
closedir($mydir);
?>
</script>

HTH.  Let me know If I can (try) to explain anything more...

Michael

Michael Layne : 9 degrees development : www.9degrees.com : 404.226.7835

Charles Ross wrote:
> Is it possible to get a PHP array to a JavaScript function?
>
> I'm trying to populate a menu based on the selection for another menu. 
> Basically it's a parent/child relationship. The user selects the 
> parent from one menu and the children of that parent appear in a 
> second menu.
>
> Getting the data from the database is done with PHP. Changing the 
> second menu would be done, I think, with JavaScript (which I'm also 
> learning as I go). I've been trying to figure out how to get the data 
> from one to the other, but haven't succeeded.
>
> Or perhaps I'm going about this in entirely the wrong way. Any 
> assistance would be appreciated.
>
> Thanks,
> Chuck Ross
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20060907/bfef1300/attachment-0001.html


More information about the FX.php_List mailing list