SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting multiple image links into DB

    what would be the easiest way to insert lets say 5 filenames in a mysql database? have 5 columns named:
    image1
    image2
    image3
    image4
    image5

    or is there a better way? sometimes the user might only have 1 image or no images at all. Sometimes more than 5 images. i havent decided yet.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean actually inserting the filenames as in an insert query?
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i mean as actually storing the data, not the queries it would take to do so.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have another table, with the primary key from the user table and a filename. So like

    Images Table
    =============
    ImageID
    UserID
    ImageName
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i got it. thanks. I don't know why I didn't think of that before.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  6. #6
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ImageID col probably not necessary...

    If the image name is unique (which it should be since you can't have /some/path.gif uploaded twice) you can have the image name be the primary key (or if you are just storing bob.gif then make the PK userid, imagename).

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unless of course every user had its own folder or something then there would be a possibility that two images might have the same name. Just playing devil's advocate. I mean in the grand scheme of things, whats one more field going to matter?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freddydoesphp
    Unless of course every user had its own folder or something then there would be a possibility that two images might have the same name. Just playing devil's advocate. I mean in the grand scheme of things, whats one more field going to matter?
    Not much, but it technically is superfluous since you really don't need it. If you store the path info, then it is unique (since /bob can only hold one file called 'joe.gif', so storing '/bob/joe.gif' is a perfect primary key). However if you do not, then you can make the primary key the combination of username and filename, in the previous case it could be 'MattR', 'joe.gif'.

    Yeah, it isn't a big deal for 90% of usage but say you're adding 100 rows a second -- it will have to do work to get the next auto_increment. Also, if you have 10 million rows the extra bytes could make some damage.

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to add one more point, and I agree with everything you have said MattR. If the script is not controlling the file names, then it would pretty lame to make a user change an image name he wants to upload because some other schmo happened to add a photo with the same name first.

    And actually I might think about making my own file names for the uploaded images to avoid this type of problem.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  10. #10
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I actually used to assign images unique names by grabbing the time(); but i noticed that some users use the image name to identify the image instead of having to load every image to see what it is. A prime examply of this is www.artistjuliannefelton.com where i used to assign the images a unique name but then the customer complained so i change it to retain the original name as he said he had no 2 images named the same. thank you very much for the advice.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual


Bookmarks

Posting Permissions

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