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

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2

    Ignore as it is a bad post cant delete


    Please don't get too mad. I am a beginner at php and pdo so here it goes. I was wondering as I am uploading multiple images to directories how would I input the image data such as directory that it is in and the path into the database. I am sorry if this is not what the forum is for and if you could please at least lead me in the right direction because no matter how I ask Google I cannot find the answer that I am looking for. There is one other thing if it is not to much to ask....

    I have the part that creates the group and in the database puts the name and id, but what I am trying to accomplish is when the admin is choosing the albums that he/she wants to add to a specific group add a corresponding group id to the album and images.

    An example let say that I want photoshop album to be apart of the group logos and the group logos has an id of 1 how do I assign a group id of 1 to photoshop?
    Last edited by natturefrk; December 18th, 2013 at 12:42 AM.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,673
    Rep Power
    1958
    Which database are you using?

    Do you know how to create the database and tables?
    do you know how SQL works?

    Basically, you will have to use the SELECT-statement to retrieve data from the database:
    SELECT fieldname1, fieldname2 FROM table

    and the INSERT-statement to store data into the database:
    INSERT INTO tabe (fieldname1,fieldname2) VALUES (fieldvalue1,fieldvalue2)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    As far as the grouping your albums...

    In your batabase, this basically refers to 2 tables. The first table meerly defines a group and it's details, but nothing to do with connected albums, just itself. The second table defines the albums and such, and has a column to meerly hold the GROUP_ID it is related with. As far as making actions in your script to add/remove albums to/from groups, you will meerly be using the UPDATE function of SQL to alter the GROUP_ID column.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,673
    Rep Power
    1958
    Originally Posted by Triple_Nothing
    In your batabase, this basically refers to 2 tables. The first table meerly defines a group and it's details, but nothing to do with connected albums, just itself. The second table defines the albums and such, and has a column to meerly hold the GROUP_ID it is related with.
    It will actually be three tables, if there is a many-to-many relation. I.E. one image can be part of more than one group as well as one group can contain several pictures.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    Originally Posted by MrFujin
    It will actually be three tables, if there is a many-to-many relation. I.E. one image can be part of more than one group as well as one group can contain several pictures.
    I am sorry that I did not explain the scheme and to answer your question MrFujin I have a basic understanding of SQL. I know how to insert a single row of data but not multiple, but just learned how to. Now on to the system. I have one db and in the db I have 3 tables. One for the album info which had album name and path, one for the image info which has album that the image is contained in, image path, thumbs path, and one for the group info has group id and group name. I am curious to know why 3 tables just to do one thing though. All I am trying to do is pick the group then the album I want to add and just add a corresponding id to those albums. I see only 2 tables that are needed. The group table and the album table. I can't think of why I could not think of using MySQL's UPDATE statement to add the right group id to the albums. I feel real stupid on that one. Now that I know how to insert multiple rows of data I can use the UPDATE statement to do as I was originally asking. Thanks for the enlightenment Triple Nothing.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    MrFujin did bring up a good point with his many-to-many. Can images or groups exist in more than 1 place? Or, could u really draw all relations out as a tree, where any item has a single parent?

    EDIT: N I guess a note to another possible 3rd table. If you sort files with ur directory structure, that would be fine, but if all images are held in main folders, then another table will need to hold file info to relate it and such since the directory that would, is not.
    Last edited by Triple_Nothing; December 18th, 2013 at 09:55 PM.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    Originally Posted by Triple_Nothing
    MrFujin did bring up a good point with his many-to-many. Can images or groups exist in more than 1 place? Or, could u really draw all relations out as a tree, where any item has a single parent?

    EDIT: N I guess a note to another possible 3rd table. If you sort files with ur directory structure, that would be fine, but if all images are held in main folders, then another table will need to hold file info to relate it and such since the directory that would, is not.
    Nevermind because this application that I am trying to build is getting more and more out of my realm of understanding with php, mysql, and pdo. I am sorry for waisting your time guys. Thanks for all the help that you have provided. Maybe it is time to throw in the towel of ever becoming a professional php developer. There are concepts of php that are very confusing to me at times. I try to find a better understanding on google, but it does not work for me because of the learner I am. It seems that any hopes of becoming a php developer are dependent on me going to school and that is just a waste of money because there is not enough demand for this.
  14. #8
  15. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,673
    Rep Power
    1958
    Learning is something that take a lot time and motivation, which can indeed be very limited if you have other kind of projects/things to do.

    Just remember that we all had our own share of asking those "stupid" questions.

    Comments on this post

    • badger_fruit agrees : We were all newbies to PHP once!
    • natturefrk agrees : I just wanted to give you a reputation point
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Indeed. And as one has said, "The worst question is the question not asked."

    If you feel it may be out of your realm, it may be, but just at this particular second. Before I learned how to truely design a fully functional photo album/gallery, I started with just the client side view, and all it was was a fetch of folder names to define the albums/categories, and when one was chosen, it just fetched everything in that folder to display. No PHP or Databases even existed with my first start.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    Originally Posted by Triple_Nothing
    Indeed. And as one has said, "The worst question is the question not asked."

    If you feel it may be out of your realm, it may be, but just at this particular second. Before I learned how to truely design a fully functional photo album/gallery, I started with just the client side view, and all it was was a fetch of folder names to define the albums/categories, and when one was chosen, it just fetched everything in that folder to display. No PHP or Databases even existed with my first start.
    Yeah I just got over zealous and jumped the gun I think. Meaning trying to learn to run before I learned how to walk. I know how to code the basic functionality of this system, but when it comes to actually displaying all the groups and albums and images is where I have my problem. I will probably have to return to this at later time when I understand how that works.

    One thing that I have in issue with though I thought I learned how to put multiple values in a database to only find out that I did not. How in the heck do you put multiple values from an array into the database.
    Seperate row for each value of course. I was searching Google for at least 2 hours trying to figure out how to do it. I got the foreach loop part and I can echo the values. I just don't know how to put that into pdo so that each value of that array will go into the database. The results i get when i tried it myself was i got all 0's in each row of my table instead f the values.
    Last edited by natturefrk; December 19th, 2013 at 12:06 PM.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Well, you say you can get the echo to work in a loop? This is all it really is, if you wish. What are you echo'ing? You can simply run a loop, with 1 INSERT statement which will only insert 1 row, but each run of the loop will insert the next. Just don't forget to add something to increment your index. Most use the variable $i starting at 0 (zero) and at the end of each run, a simple $i++; will knock it up 1.

    Comments on this post

    • natturefrk agrees : I just wanted to give you a reputation point
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  22. #12
  23. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi natturefrk,

    it would be very, very helpful if you posted your actual code so that we can point out concrete errors and give concrete advice.

    Otherwise, this will be a very theoretical discussion.

    Comments on this post

    • natturefrk agrees : You make a very good point jacques. I will keep that in mind in future posts. I gave you a rep point also.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  24. #13
  25. Confused badger
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2009
    Location
    West Yorkshire
    Posts
    1,112
    Rep Power
    487
    natturefrk

    Unfortunately, trial and error play a massive part in programming as I am sure everyone here will attest to!

    Perseverance is key to success!

    You said that you have it "sort of" working at the moment; May I suggest that you get into the habit of sending the values of your variables out either to-screen or to a log file so you can actually see what is going on during the script execution.

    That way, you should be able to see clearer where and why things aren't quite going as planned!

    As triple_nothing has said, a simple loop, inserting 1 record at a time will be sufficient for the basics (and, if something is bad in the data, a 1 at a time insert might end up importing more than if you try to do the lot at once!)

    Good luck and do not give up!!

    Comments on this post

    • natturefrk agrees : thanks for your help
    "For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
    - George Orwell, 1984
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    87
    Rep Power
    2
    I feel real stupid right now after banging my head on the wall for hours it was getting very frustrating . I figured out my problem though. I was putting
    PHP Code:

    $groups 
    $_POST['group_select'];
        
        
    $album_path '../test/test/test';
        
            
    //this line here
        
    $sql "INSERT into upload_album VALUES(:album_name, :album_path)";
        
             
    //and this line here
        
    $q $db->prepare($sql)
        
        foreach (
    $groups as $key => $value) {
        
            
    $q->execute(array(':album_name' => $value':album_path' => $album_path));
            
        }
        
        exit(); 
    (look for php comments in the code for the specific lines that I am talking about)inside of my foreach loop and I remembered when I tried putting all the html for a select tag inside of a while loop it did not work either and I remembered how I fixed it too and just applied to this foreach loop. Once I put the $sql and the prepare statement outside the foreach loop it worked like a charm. THANK YOU for all your help and the words of encouragement. Also you guys made me feel like I wasn't alone in this not always getting it right with php. Thank you.
    Last edited by natturefrk; December 19th, 2013 at 10:45 PM. Reason: Forgot something

IMN logo majestic logo threadwatch logo seochat tools logo