Web Analytics Made Easy -
StatCounter How to post comments to photos - CodingForum

Announcement

Collapse
No announcement yet.

How to post comments to photos

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to post comments to photos

    Hi there,im a new php develepor and im wondering how to post a comment to a picture im currently viewing within a photo album,
    i have a comments table in my database containing,
    >user_id (int)
    >photo_id (int)
    >album_id (int)
    >comment (var char)
    >comment_id (pri key) (a.i) (int)

    so far the only fields i cannot fill in are the photo_id and album_id, i want to put them on the variables $photoId and $albumId, i have no idea how to set them thus allowing me to insert them into the database. i got user_id from the session, comment from the text area, and comment_id is auto increment so no need to worry about that...im just looking for a bare essential way of doing this, to get a working version, a dirty version if u must.

    anyways, after you help me set these photo_id and album_id variables i should be okay on my own.

    thanks in advance

  • #2
    comment_id appears to be a surrogate key. That means you don't care about getting it (before an insertion), you're database should use an auto-incrementing number. If you don't use this, a composite key of user_id, photo_id and (possibly) album_id would be required, but that depends on if a user can comment more than once which requires a flattening table to establish a many to many relationship (in which case the comment_id is the easiest route).
    As for the album_id, thats a matter of how the rest is set up. If you can have multiple photo_id's with the same key, this would indicate that album_id would be required. If photo_id is a surrogate key, there is no need for the album_id, since the photo table (or whatever it would be called), would include a foreign key to album_id.

    I have no idea where you're album_id is supposed to come from, that would be up to you to select the appropriate data. I would assume that its a foreign key in the photo table - that just makes the most sense to me, unless you can have many pictures in many albums, then it would be another flattening table.

    Needless to say, you don't really have enough information here to form valid assumptions for the route you'll need to follow. I'm also debating if this should be moved to the sql forum, but I'll wait to see exactly what we're looking at first.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

    Comment

    Working...
    X