dcsimg
Results 1 to 10 of 10

Thread: PHP code not working?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,922

    PHP code not working?

    I have a small PHP file in which there is a HTML menu structure using <ul> & <li> elements. This web page is a simple photo gallery where all the images are on the web server's file system. The problem I'm having is that when a menu item is clicked on the file directory should change and then the PHP routine should load the screen with images but that's not happening and I don't know why and I'm not sure how to debug it. I have attached the file.

    Thanks in advance,
    Attached Files Attached Files
    Blake

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,177

    Re: PHP code not working?

    It's been a long time since I've done anything in php, so sorry for the possibly stupid question, but what is "</php" tag (my Google-fu can't seem to find anything either)?

    Can you show the resulting HTML from this page? To me, it looks like you're going to end up with an onclick event on your anchors that do nothing.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,730

    Re: PHP code not working?

    Quote Originally Posted by kfcSmitty View Post
    It's been a long time since I've done anything in php, so sorry for the possibly stupid question, but what is "</php" tag (my Google-fu can't seem to find anything either)?
    Should be the end of the php script... there should be an opening <?php> tag at the start of the PHP script, and a closing </php> one at the end. Much like <?asp></asp>.

    @Blake... can you just post the code? really don't feel like downloading a file and then having to rummage around in my download folder for the file...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,922

    Re: PHP code not working?

    tech,

    That's not how the tags are. It's <?php ... ?>.

    Here is the PHP script.

    Code:
    <?php
        $dir = "img/Cats/Resized/";
    ?>
    <!DOCTYPE html>
    <html>
    
    <head>
        <title>Memories</title>
    
        <link type="text/css" rel="stylesheet" href="css/gallery.css">
        <link type="text/css" rel="stylesheet" href="css/style.css">
    </head>
    
    
    <body>
        <h1>Memories</h1>
    
        <div class="categories">
            <nav>
                <ul>
                    <a href="#" onclick="</php $dir='img/Me/'; ?>">
                        <li>Me</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Cats/Resized/'; ?>">
                        <li>Cats</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Friends/'; ?>">
                        <li>Friends</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Trips/'; ?>">
                        <li>Trips</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Montana/'; ?>">
                        <li>Montana</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Local/'; ?>">
                        <li>Local Area</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Misc/'; ?>">
                        <li>Miscellaneous</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Videos/'; ?>">
                        <li>Videos</li>
                    </a>
                </ul>
            </nav>
        </div>
    
        <div>
            <div class="mainDiv" style="overflow: none; margin-left: 70px">
                <?php 
                        $files = scandir($dir);
                        $x = 0;
                    
                        for($i = 0; $i < count($files); $i++) {
                            if ($files[$i] != '.' && $files[$i] != '..') {
                                if ($x == 7) {
                                    echo "<br>";
                                    $x = 0;
                                }
                                echo "<div class='imgContainer'>" .
                                         "<div class='gallery'>" . 
                                             "<a href='$dir$files' onclick='openModal()'><img src='$dir$files[$i]'></a>" .
    //                                         "<a href='$dir$files' data-lightbox='$files'><img src='$dir$files[$i]'></a>" .
                                         "</div>" . 
                                     "</div>";                                
    
                                $x++;
                            }
                        }
                    ?>
            </div>
        </div>
    </body>
    
    </html>
    Blake

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,922

    Re: PHP code not working?

    tech,

    That's not how the tags are. It's <?php ... ?>.

    Here is the PHP script.

    Code:
    <?php
        $dir = "img/Cats/Resized/";
    ?>
    <!DOCTYPE html>
    <html>
    
    <head>
        <title>Memories</title>
    
        <link type="text/css" rel="stylesheet" href="css/gallery.css">
        <link type="text/css" rel="stylesheet" href="css/style.css">
    </head>
    
    
    <body>
        <h1>Memories</h1>
    
        <div class="categories">
            <nav>
                <ul>
                    <a href="#" onclick="</php $dir='img/Me/'; ?>">
                        <li>Me</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Cats/Resized/'; ?>">
                        <li>Cats</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Friends/'; ?>">
                        <li>Friends</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Trips/'; ?>">
                        <li>Trips</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Montana/'; ?>">
                        <li>Montana</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Local/'; ?>">
                        <li>Local Area</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Misc/'; ?>">
                        <li>Miscellaneous</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Videos/'; ?>">
                        <li>Videos</li>
                    </a>
                </ul>
            </nav>
        </div>
    
        <div>
            <div class="mainDiv" style="overflow: none; margin-left: 70px">
                <?php 
                        $files = scandir($dir);
                        $x = 0;
                    
                        for($i = 0; $i < count($files); $i++) {
                            if ($files[$i] != '.' && $files[$i] != '..') {
                                if ($x == 7) {
                                    echo "<br>";
                                    $x = 0;
                                }
                                echo "<div class='imgContainer'>" .
                                         "<div class='gallery'>" . 
                                             "<a href='$dir$files' onclick='openModal()'><img src='$dir$files[$i]'></a>" .
                                         "</div>" . 
                                     "</div>";                                
    
                                $x++;
                            }
                        }
                    ?>
            </div>
        </div>
    </body>
    
    </html>
    Blake

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,730

    Re: PHP code not working?

    Quote Originally Posted by blakemckenna View Post
    tech,

    That's not how the tags are. It's <?php ... ?>.

    Here is the PHP script.

    Code:
    <?php
        $dir = "img/Cats/Resized/";
    ?>
    <!DOCTYPE html>
    <html>
    
    <head>
        <title>Memories</title>
    
        <link type="text/css" rel="stylesheet" href="css/gallery.css">
        <link type="text/css" rel="stylesheet" href="css/style.css">
    </head>
    
    
    <body>
        <h1>Memories</h1>
    
        <div class="categories">
            <nav>
                <ul>
                    <a href="#" onclick="</php $dir='img/Me/'; ?>">
                        <li>Me</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Cats/Resized/'; ?>">
                        <li>Cats</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Friends/'; ?>">
                        <li>Friends</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Trips/'; ?>">
                        <li>Trips</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Montana/'; ?>">
                        <li>Montana</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Local/'; ?>">
                        <li>Local Area</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Misc/'; ?>">
                        <li>Miscellaneous</li>
                    </a>
                    <a href="#" onclick="</php $dir='img/Videos/'; ?>">
                        <li>Videos</li>
                    </a>
                </ul>
            </nav>
        </div>
    
        <div>
            <div class="mainDiv" style="overflow: none; margin-left: 70px">
                <?php 
                        $files = scandir($dir);
                        $x = 0;
                    
                        for($i = 0; $i < count($files); $i++) {
                            if ($files[$i] != '.' && $files[$i] != '..') {
                                if ($x == 7) {
                                    echo "<br>";
                                    $x = 0;
                                }
                                echo "<div class='imgContainer'>" .
                                         "<div class='gallery'>" . 
                                             "<a href='$dir$files' onclick='openModal()'><img src='$dir$files[$i]'></a>" .
                                         "</div>" . 
                                     "</div>";                                
    
                                $x++;
                            }
                        }
                    ?>
            </div>
        </div>
    </body>
    
    </html>
    Yeah, clear;y it's been a while... but any waysw.... I see what he's talking about now:
    {code]
    <a href="#" onclick="</php $dir='img/Videos/'; ?>">
    [/code]
    Those php tags.... what are those about?


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Candon City, Ilocos Sur, Phils.
    Posts
    11,036

    Re: PHP code not working?

    Quote Originally Posted by blakemckenna View Post
    tech,

    That's not how the tags are. It's <?php ... ?>
    And yet you used "</php".
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,922

    Re: PHP code not working?

    I see what you're saying now...thanks for the 2nd set of eyes!
    Blake

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,730

    Re: PHP code not working?

    I'm not sure it would matter anyways.... PHP is a server side script and the onClick is JS which would be client-side... so I'm not sure what the click is supposed to look like or do.
    because if this:
    Code:
    <a href="#" onclick="</php $dir='img/Videos/'; ?>">
    was supposed to be this:
    Code:
    <a href="#" onclick="<?php $dir='img/Videos/'; ?>">
    then it would render like this:
    Code:
    <a href="#" onclick="">
    since nothing is echoed back to the client from the PHP code... so I don't know what is supposed to do what in the code.



    wait... are you expecting that PHP code to run when you click the link? ooooh..... ooohhh..... yeah... that's not how that works there. PHP runs on the server as the page is rendered. Once it is sent to the client, that's it. It's not like JQuery or React or anything like that which can react to client side actions. It's 100% pure server side, like ASP (classic). So if you're expecting it to reset $dir, and then the rest of the PHP code to re-run and re-generate your file listing.... yeah... not going to happen. You'll need to re-think your code there.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    4,922

    Re: PHP code not working?

    Can jQuery or pure Javascript handle file system processing like I want?
    Blake

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width