#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2

    Delete images from drop down menu


    As I am pretty sure that most of you know because of my many annoying posts my system is working out of directories. I am trying to populate two option tags with the directory and then once the directory is selected the second option tag will populate with the images from that directory. Then the site admin will choose which pictures they want to delete. Ok so lets say that I pick a directory called photoshop and in that directory there are four images(img1.jpg, img2.png, img3.gif, and img4.jpeg) then that would mean that as soon as I pick photoshop the second option tag would populate those images. I have the code all and ready but the second option tag is not populating with any images from the directory that have chose which all these paths are stored in the database. I have used the where clause and that did not help me unfortunately. I really am stuck on what to do. Do the option tags have to be on different pages? Here is the code:

    PHP Code:
    function grab_albums($db){
        
        
    $sql "SELECT * FROM `Group_1`";
                
        
    $q $db->prepare($sql);
                
        echo 
    '<p>Select Album to Delete Images from:<br /><br /><select name="albums"><option value="">Select One...</option>';
                
        if(
    $q->execute()){
                    
                    
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                    
                                            
                
    $a_name $row['a_name'];
                
                
    $path $row['dir_path'];
                        
                            
                echo 
    '<option value="'.$path.'">'.$a_name.'</option>';
                        
                        
            }
                
                
                    echo 
    '</select><br /><br />';
                
                
        }
        

        
    $db null;
        
    }


    function 
    remove_image_setup($db$path){
        
        
    $path grab_albums($db);
        
        
    $sql "SELECT * FROM `Group_2` WHERE image_path = :path";
                
        
    $q $db->prepare($sql);
                
        echo 
    '<p>Select Image to Remove:<br /><br /><select name="remove_image"><option value="">Select One...</option>';
                
        if(
    $q->execute(array(':path' => $path))){
                    
                    
            while(
    $row $q->fetch(PDO::FETCH_ASSOC)){
                    
                                            
                
    $path $row['image_path'];
                
                
    $image $row['image_name'];
                        
                            
                echo 
    '<option value="'.$path.'">'.$image.'</option>';
                        
                        
            }
                
                
                    echo 
    '</select><br /><br />';
                
                
        }
        

        
    $db null;


    Last edited by natturefrk; March 9th, 2013 at 09:26 AM. Reason: reformating a part of the question
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    Just a few questions:

    1.) You've only showed us the code to fetch and print the data. Where is the code to check if a directory has been selected?

    2.) I see no trigger on the directory options. Are you doing this some other way (JS/jQuery perhaps)? Or have do you have no trigger?

    3.) Because you've only showed us the code to fetch and print the data, I'm assuming that you're pretty sure that the problem lies in those two functions. Am I correct?

    4.) Can you show us a live version? If you can, just post ALL of your code here and forget about the questions above.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    I apologize for being to general and I just found out yesterday that I have to involve JSON, JQuery, or JS to get this working properly which I have 0 knowledge of any those languages.

    The answer to question number one is I have none as of yet which I got so caught up in getting it to work that I forgot that important factor.


    Answer to number 3 would be no I do not think that the problem lies with the functions themselves. I really think that it involves the fact that I am newb and don't have the knowledge as of yet to pull a system such as this off.


    I will post the code that correlates to the above question mind you that the part that displays on the webpage is wrong at least the parsing part because I have done very little to it because I was solely concentrating on getting the functions to work properly.


    PHP Code:

    //this is where the functions are called and then form data is parsed

    <?php

    include 'init.php';

    echo 
    $_POST['albums'];

    /*if(isset($_POST['remove'])){
        
        $image = $_POST['remove_image']; 
        
        $path = 'upload/upload/'.$_POST['albums'].'/'.$_POST['remove_image'];
        
        if(unlink($path) === true){
        
            
            if(remove_image($path, $db) == true){
            
            
                echo 'You have deleted '.$dir.' successfully!!<br /><br /><a href="admin_panel.php">Admin Panel</a>';
            
            
            }else{
            
            
                echo 'There was an error with deleting '.$dir.'!!<br /><br /><a href="edit_album.php">Go Back</a>';
            
            
            }
        
        
        }
        

    }*/

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <title>Conforming XHTML 1.0 Strict Template</title>

    </head>

    <body>
        
        
        <div style="margin:auto; width:500px; text-align:center;">
            
            
            <form method="post" action="">            
                
                
                <?php grab_albums($db); ?><br /><br />
                        
                        
                <input type="submit" name="remove" value="remove" />
            
                    
            </form>
            
            
        </div>


    </body>
    </html>
    The functions are in the OP

    Actually I am thinking about chucking this system and starting with something else that is a bit more my speed.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    Right. Well, because I'm feeling generous today, I'll write up a quick example for you.

    You've actually done most of the work. All that needs to be done is the front-end side of things and maybe a few alterations to the back-end.

    Create a separate JS file, which you will include in your document.

    Code:
    //firstly, declare your function
    //this function will perform a redirect
    //and will pass the selected dir through the URL query ($_GET)
    //which we'll play with, in PHP
    
    function changePhoto( directory )
    {
           if ( directory == "" )
           {
                 //no directory was passed so we can finish up here
                 return;
           }
           
           //declare our redirect target URL
           targetURL = 'http://your-site.com/remove_image.php?dir=' + directory;
           //do redirect
           window.location = targetURL;
    }
    So that's most of your JS done. Now just some amendments to your PHP:

    PHP Code:
    function grab_albums($db)
    {
        
    $sql "SELECT * FROM `Group_1`";
        
    $q $db->prepare($sql);
        echo 
    '<p>Select Album to Delete Images from:<br /><br /><select name="albums"><option value="">Select One...</option>';

        if(
    $q->execute())
        {
            while(
    $row $q->fetch(PDO::FETCH_ASSOC))
            {
                
    $a_name $row['a_name'];
                
    $path $row['dir_path'];
                echo 
    '<option onclick="javascript:changePhoto( \'' .$path'\' );" value="'.$path.'">'.$a_name.'</option>';
            }

            echo 
    '</select><br /><br />';
            
    //check if a path was passed (through the URL query)
            
    if ( empty( $_GET['dir'] ) === false )
            {
                
    //call the other function to print second select box
                
    remove_image_setup$db$_GET['dir'] );
            }
        }

        
    $db null;

    That should do the whole second <select> thingy for you.

    Oh, and make sure you include that JS file in your original HTML doc. So put
    Code:
    <script type="text/javascript" src="pathToYourExternalJSFile.js"></script>
    in the <head> section of your HTML and change "pathToYourExternalJSFile.js" to the actual path to your actual JS file (that you created).

    Happy Coding!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    I thank you and FULLY appreciate you for all your help and the time you have commited, but I am to stupid to figure this out. One change and my whole system is falling to pieces. Nothing works now, not the upload, deleting albums, nor deleting the images. I am NOT blaming you in anyway shape or form, this all due to my lack of knowledge on how to properly use everything. I know that something is wrong with my logic somewhere, I just cant figure out where. I am pretty sure that my whole system can be better coded. I am to frustrated at this point to really fix anything that is if I have the ability to. I am sorry for any inconvenience that I may have caused you. I am chucking the system and moving on to something that I know better, dont know what yet but I will figure it out soon or later. Thanks AGAIN!!!!!!
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    You know, you should just hire someone. The task isn't very complicated so put it on Bountify or just find a cheap freelancer. That way, you'll have it done in no time xD

IMN logo majestic logo threadwatch logo seochat tools logo