Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Outputting Javascript array values

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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
•••
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
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back