PDA

Click to See Complete Forum and Search --> : [RESOLVED] - Gallery


Dim
Jun 12th, 2005, 03:31 PM
I've been attempting this for a couple of days now. I think it's time to ask for assistance.

I have a mysql db and each tuple contains an image name attribute. On my site, I pull that name out just fine and can store the names in an array. I can even display all the images in that table. But I need to have them display one at a time.

What I need to do is make a slideshow of sorts. I would prefer not to refresh the entire page. I found some nice JS slideshows, but PHP doesn't seem to want to cooperate with JS. Like with most JS slideshows they want the image names stored in an array also. But when I try to move elements from the php array to the JS array things don't work out.

Any suggestions as to how I can create this gallery using just php?
Thank you.

ALL
Jun 12th, 2005, 03:50 PM
can you give a link to a "pre" page? like the page with the JS and how you want the design (including some pics)?

we can get a much better view of what you want that way ;)

Dim
Jun 12th, 2005, 03:54 PM
Well simply put, how can I copy over from a PHP array to a JS array.

ALL
Jun 12th, 2005, 04:05 PM
this article should be EXACTLY what you are looking for:
http://www.hscripts.com/tutorials/php/phpArrayToJS.php
:thumb:

Dim
Jun 12th, 2005, 04:22 PM
function view_project($project) {
$projecttemp = $_GET['project'];
$thetable = "album";
$query = "SELECT * FROM $thetable WHERE(project='$projecttemp')";
$result = @mysql_query($query);
$record = @mysql_fetch_assoc($result);
$num = @mysql_numrows($result);
$i=0;

while ($i < $num) {
$images = @mysql_result($result,$i,"image");
$comment = @mysql_result($result,$i,"text");
$file_array[] = "pictures/$images";
print "fadeimages.push(\"pictures/$images\" );";
$i++;
}


//SET 1) IMAGE PATHS, 2) optional link, 3), optional link target:
//fadeimages[0]=["cabin.gif", "", ""] //plain image syntax
//fadeimages[1]=["framing_ani2.gif", "", ""] //image with link syntax
//fadeimages[2]=["kitchen_ani.gif", "", ""] //image with link and target syntax
?>
....The rest is JS code.



Can't get it working. For starters the print statement actually just prints the code out. Doesn't execute it.

Any idea ALL?

ALL
Jun 12th, 2005, 04:54 PM
well, you cannot pass an array form php straight to JS, because there is no direct link from the client and the server. you would have to echo all the array values into the webpage.

try this:

function view_project($project) {
$projecttemp = $_GET['project'];
$thetable = "album";
$query = "SELECT * FROM $thetable WHERE(project='$projecttemp')";
$result = @mysql_query($query);
$record = @mysql_fetch_assoc($result);
$num = @mysql_numrows($result);
$i=0;

while ($i < $num) {
$images = @mysql_result($result,$i,"image");
$comment = @mysql_result($result,$i,"text");
$file_array[] = "pictures/$images";
echo "fadeimages[$i] = \"pictures/$images\";\n";
$i++;
}


//SET 1) IMAGE PATHS, 2) optional link, 3), optional link target:
//fadeimages[0]=["cabin.gif", "", ""] //plain image syntax
//fadeimages[1]=["framing_ani2.gif", "", ""] //image with link syntax
//fadeimages[2]=["kitchen_ani.gif", "", ""] //image with link and target syntax
?>
....The rest is JS code.

or something like php has where you can just do "$whatever = array("one","two","three");" but i dont know JS :(

visualAd
Jun 13th, 2005, 01:29 AM
Like ALL said, you need to echo each individual statement. You als need to ensure that the Javascript code is inside script tags.

?>
<script type="text/javascript">
<!--
var myarray = Array(<?php echo(count($myarray)) ?>);

<?php for($x = 0; $x < count($myarray); $x++): ?>
myarray[<?php echo($x) ?>] = <?php echo(htmlspecialchars($myarray[$x])) ?>;
<?php endfor; ?>
//-->
</script>

Dim
Jun 13th, 2005, 05:28 PM
function view_project($project) {
$projecttemp = $_GET['project'];
$thetable = "album";
$query = "SELECT * FROM $thetable WHERE(project='$projecttemp')";
$result = @mysql_query($query);
$record = @mysql_fetch_assoc($result);
$num = @mysql_numrows($result);
$i=0;
?>

<script type="text/javascript">
var slideshow_width='600px' //SET IMAGE WIDTH
var slideshow_height='400px' //SET IMAGE HEIGHT
var pause=3000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)
var fadeimages=new Array()
<?

while ($i < $num) {
$images = @mysql_result($result,$i,"image");
$comment = @mysql_result($result,$i,"text");
//$file_array[] = "pictures/$images";
$images = "pictures/$images";
//SET 1) IMAGE PATHS, 2) optional link, 3), optional link target:
?>fadeimages[<?echo "$i";?>]=["<?echo "$images";?>", "", ""] //plain image syntax<?
$i++;
}
?>

...Rest of JS Code


Ok I am so close. I have the first image showing, but the rest are not. Almost as through the JS array fills is at [0] but not any further.
Any ideas?
Thanx

ALL
Jun 13th, 2005, 05:50 PM
try this, and tell us what it spitts out:
function view_project($project) {
$projecttemp = $_GET['project'];
$thetable = "album";
$query = "SELECT * FROM $thetable WHERE(project='$projecttemp')";
$result = @mysql_query($query);
$record = @mysql_fetch_assoc($result);
$num = @mysql_numrows($result);
$i=0;
while ($i < $num) {
$images = @mysql_result($result,$i,"image");
$comment = @mysql_result($result,$i,"text");
//$file_array[] = "pictures/$images";
$images = "pictures/$images";
//SET 1) IMAGE PATHS, 2) optional link, 3), optional link target:
?>fadeimages[<?echo "$i";?>]=["<?echo "$images";?>", "", ""] //plain image syntax<?
echo "\n$num --- $i"
$i++;
}
?>

Dim
Jun 13th, 2005, 05:54 PM
Just tried it, nothing comes through. If I add any echo statements into the while loop, the first image also doesn't display anymore. I am so confused. :)
I checked the $num prior to the loop and it reports correctly.

ALL
Jun 13th, 2005, 05:57 PM
well... what was it spitting out, could you upload the script and give us the url to see what it spitts out?

Dim
Jun 13th, 2005, 06:12 PM
Don't know what I managed to change that would make a difference, but it works now. Thank you ALL and visualAd.

For anyone that might need similar help:

function view_project($project) {
$projecttemp = $_GET['project'];
$thetable = "album";
$query = "SELECT * FROM $thetable WHERE(project='$projecttemp')";
$result = @mysql_query($query);
$record = @mysql_fetch_assoc($result);
$num = @mysql_numrows($result);
$i=0;
?>
<script language="JavaScript1.2" type="text/javascript">
var slideshow_width='600px' //SET IMAGE WIDTH
var slideshow_height='400px' //SET IMAGE HEIGHT
var pause=3000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)
var fadeimages=new Array()
<?
while ($i < $num) {
$images = @mysql_result($result,$i,"image");
$images = "pictures/$images";
?>fadeimages[<?echo "$i";?>]=["<?echo "$images";?>", "", ""] //plain image syntax
<?$i++;
}
?>

...Rest of JS Code inside the php function...

ALL
Jun 13th, 2005, 06:22 PM
arnt you missing a simi-colin on the javascript? shouldnt it read like this:
... ", "", ""]; //plain image syntax ...

Dim
Jun 13th, 2005, 07:48 PM
I'm no JS expert, but looking at the code for this gallery, I don't think JS uses semi-colons. I added it just to see what happens, nothing, result is still the same. I'm just glad that we managed to figure this out. Thanx again.

ALL
Jun 13th, 2005, 07:52 PM
well, i am horrable at JS, just thought JS required semi-colins at the end of statments, could be wrong though ;)

visualAd
Jun 14th, 2005, 12:54 AM
Javascript does require terminating semi colons. If you want your script to work in Firefox you'll need to put them in.

Could you post the HTML output of your script and the PHP code which generates it?