Outputting Javascript array values

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Rudy

Established Member
Impact
16
Hey guys,
There's a little PHP here, but I think this is a javascript issue... I am creating a javascript array, and within a php while() loop, I am adding values to the array and then am trying to output the results. However, what I want outputted to the browser is not being sent.

I am trying to output an image, but it is not happening.

Any ideas why this is happening?

Code:
<?PHP
/*
Author: David White
Date Started: 02/06/2007
Description: 	This script will allow a user to browse through pictures
		in a directory to select one picture. It will place all of the contents
		in a directory into an array which will be displayed one-by-one on the click
		of a button.
*/

// Set the Directory Location
$directory = opendir('../premier_images/');

// Put every picture in the directory into an array
echo "<script type=\"text/javascript\">
		var output = new Array()
		var i = 0;
	";
while ($picture = readdir($directory)) {
	echo "	output[i] = " . $picture . "
		document.write('
			<div id='+output[i]+' style=\'<!-- display:none;-->align=center;valign=center;\'>
				<img src=\'../premier_images/'+output[i]+\'>
				<br />
			</div>
			');
		i++;
		document.write(i);
		";
}
// ignore this next line... it has a php function that I still need to switch over to a javascript function.... it's not causing any problems
echo "</script><br /><br /><input type='button' value='Next Photo' onClick=\"next_photo_gallery('".current($output)."', '".next($output)."')\">";
?>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
erm... I think the problem is that your while loop is in php, but you are increasing var i in javascript lol.

Lets see what I can do:
Code:
<?PHP
/*
Author: David White
Date Started: 02/06/2007
Description: 	This script will allow a user to browse through pictures
		in a directory to select one picture. It will place all of the contents
		in a directory into an array which will be displayed one-by-one on the click
		of a button.
*/

// Set the Directory Location
$directory = opendir('../premier_images/');

// Put every picture in the directory into an array
echo "<script type=\"text/javascript\">
		var output = new Array()
	";
$i = 0;
while ($picture = readdir($directory)) {
	echo "	output[".$i."] = " . $picture . "
		document.write('
			<div id='+output[".$i."]+' style=\'<!-- display:none;-->align=center;valign=center;\'>
				<img src=\'../premier_images/'+output[".$i."]+\'>
				<br />
			</div>
			');
		document.write(".$i.");
		";
$i++;
}
// ignore this next line... it has a php function that I still need to switch over to a javascript function.... it's not causing any problems
echo "</script><br /><br /><input type='button' value='Next Photo' onClick=\"next_photo_gallery('".current($output)."', '".next($output)."')\">";
?>
try that... I just did the "$i" bit in php instead of javascript...

It all seems a bit ott to be honest though... wouldn't it be much easier to do the whole thing in PHP?
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back