Results 1 to 16 of 16

Thread: [RESOLVED] - Gallery

  1. #1

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Resolved [RESOLVED] - Gallery

    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.
    Last edited by Dim; Jun 13th, 2005 at 06:13 PM.
    Dim

  2. #2
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Gallery

    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
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  3. #3

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Re: Gallery

    Well simply put, how can I copy over from a PHP array to a JS array.
    Dim

  4. #4
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Gallery

    this article should be EXACTLY what you are looking for:
    http://www.hscripts.com/tutorials/php/phpArrayToJS.php
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  5. #5

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Re: Gallery

    Code:
    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?
    Dim

  6. #6
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Gallery

    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:

    PHP Code:
    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
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Gallery

    Like ALL said, you need to echo each individual statement. You als need to ensure that the Javascript code is inside script tags.
    PHP Code:
    ?>
    <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>
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Re: Gallery

    Code:
    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
    Dim

  9. #9
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Gallery

    try this, and tell us what it spitts out:
    PHP Code:
    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++;
        }        
    ?>
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  10. #10

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Re: Gallery

    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.
    Dim

  11. #11
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: Gallery

    well... what was it spitting out, could you upload the script and give us the url to see what it spitts out?
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  12. #12

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Re: Gallery

    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:
    PHP Code:
    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...
    Dim

  13. #13
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: [RESOLVED] - Gallery

    arnt you missing a simi-colin on the javascript? shouldnt it read like this:
    Code:
    ... ", "", ""]; //plain image syntax ...
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  14. #14

    Thread Starter
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620

    Re: [RESOLVED] - Gallery

    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.
    Dim

  15. #15
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: [RESOLVED] - Gallery

    well, i am horrable at JS, just thought JS required semi-colins at the end of statments, could be wrong though
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  16. #16
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] - Gallery

    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?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width