Results 1 to 2 of 2

Thread: Implementing a Like Button

  1. #1
    Join Date
    Apr 2014

    Implementing a Like Button

    So I'm trying to implement a like button for images on my site. But I'm having a little trouble figuring out how it goes.

    So far, I have this on the SQLI side of things :
    CREATE TABLE if not exists `likes` (
                 `id` int(11) NOT NULL AUTO_INCREMENT,
                 `liked_image_id` varchar(300) NOT NULL,
                 `liker_username` varchar(50) NOT NULL,
                  `liked_unliked` enum('0','1') NOT NULL, DEFAULT '0'
                   PRIMARY KEY (`id`)
    Where `id` is the id of the like,
    `liked_image_id` is the id of the image being liked,
    `liker_username` is the username of the user clicking the like button,
    `liked_unliked` is whether or not that user has liked the image (1 for liked, 0 for unliked [to make sure users only vote once]).

    So...is what I have so far even correct? Like I said, I'm trying to get it so that users can click the like button and like image, but only once. Any help is appreciated. Thanks

  2. #2
    Join Date
    Aug 2004
    Looks workable to me. I might consider using -1 for dislikes, allowing the possibility of a simple SUM() to get a net result if/when needed. (It's also a bit more obvious what the two values are, in that case.)

    Also, I'd put a unique index on the combination of liked_image_id and liker_username columns so as to prevent, at the data layer, multiple ratings of the same image by the same user.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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