Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-06-2006, 09:38 AM   PM User | #1
pavinder
Regular Coder

 
Join Date: Mar 2005
Posts: 115
Thanks: 3
Thanked 0 Times in 0 Posts
pavinder is an unknown quantity at this point
PHP variables to Javascript variables - quick question

I have a program written in Javascript and fully functioning which takes a user-selected directory name and then displays all the photos in that directory in a certain format.

I am now wanting to expand the program to allow users to optionally enter their own strings and the program will use all the photos from www.flickr.com which use that string as a tag.

I have a PHP interface to flickr (called PHPflickr) which collects all the relevant photo urls. I now need to get these images back into my Javascript so I can process them using the existing functions (rather than rewrite all my functions in PHP code and have two sets of functions in the program).

I found on another thread a means to do this for a date variable:
Code:
var jsArray = new Array(
<?php
$length = count($monthDataArray);
for ($i = 0; $i < $length; $i++)
{
echo '"' . addslashes($monthDataArray[$i]) . '"' . (($i < $length - 1) ? ',' : '') . "\n";
}
?>
but being completely new to PHP I'm not sure what "addslashes" might be or what formatting will be necessary if I am starting with an array of urls.

I tried:
Code:
<script type="text/javascript">
<!--

var maxxarray = new Array(
<?php
$length = count($maximgsarray);
for ($i = 0; $i < $length; $i++)
{
echo '"' . $maximgsarray[$i] . '"' . (($i < $length - 1) ? ',' : '') . "\n";
}
?>

for (i=1; i <= 12; i++) 
 {      
 document.write(maxxarray[i]+"<br>");
 }
//-->
</script>
inside my page at:
http://www.moonmilk.org/worlds/testflickr.php
but the routine above does not seem to be working. No output.

Could some kind soul advise me where I am going wrong? Each array element is a url in the form:
"http://static.flickr.com/filename.jpg"

My full page code is:
Code:
<html>
<head>
<title>PHP flickr images test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="hey there">

<script type="text/javascript">
<!--

var maximgct=8;
var maximgsarray=new Array(maximgct);

//-->
</script>

</head>
<body>

<?php
require_once("phpFlickr/phpFlickr.php");
$maximgs = 12;
// Create new phpFlickr object
$f = new phpFlickr("fbc2211a8778e91cd26d3de027eac206");

// echo "maximgcount is  $maximgs total";
echo "<p>photos tagged with \"cloud\" and maximum of $maximgs<br>\n";
// Search by the single tag "cloud"
$photos_red = $f->photos_search(array("tags"=>"cloud", "sort"=>"relevance", "per_page"=>$maximgs));
foreach ($photos_red['photo'] as $photo) {
    // Build image and link tags for each photo
    $val1= "http://www.flickr.com/photos/$photo[owner]/$photo[id]";
    echo "<a href=http://www.flickr.com/photos/$photo[owner]/$photo[id]>";
    $val2= $f->buildPhotoURL($photo, "thumbnail");
    echo "<img border='0' alt='$photo[title]' " . "src=" . $f->buildPhotoURL($photo, "thumbnail") . ">";        
    echo "</a>";
        $i++;
        $maximgsarray[i]=$val1;
        echo "<br>$maximgsarray[i]<br>$val2<br>";
        // If it reaches the 11th photo, insert a line break
        if ($i % 10 == 0) {
            echo "<br>\n";}
}
echo "</p>\n";
?> 

<script type="text/javascript">
<!--

var maxxarray = new Array(
<?php
$length = count($maximgsarray);
for ($i = 0; $i < $length; $i++)
{
echo '"' . $maximgsarray[$i] . '"' . (($i < $length - 1) ? ',' : '') . "\n";
}
?>

for (i=1; i <= 12; i++) 
 {      
 document.write(maxxarray[i]+"<br>");
 }
//-->
</script>
    
</body>
</html>
Many thanks.

Last edited by pavinder; 05-06-2006 at 09:42 AM..
pavinder is offline   Reply With Quote
Old 05-07-2006, 04:30 AM   PM User | #2
pavinder
Regular Coder

 
Join Date: Mar 2005
Posts: 115
Thanks: 3
Thanked 0 Times in 0 Posts
pavinder is an unknown quantity at this point
Don't worry....problem resolved:

A missing "$" sign and missing "'" marks when assigning the variables.
pavinder is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:26 PM.


Advertisement
Log in to turn off these ads.