Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:33:34+00:00 2026-05-30T20:33:34+00:00

I’ve been trying to find an example online of a Facebook style Like button

  • 0

I’ve been trying to find an example online of a Facebook style “Like” button but have not been able to find anything like this. What I would like to do is, place a button below an image which the user can press. Once pressed it will increment a value in the database for the image’s record, and then reflect the addition on the page by adding + 1 to the existing amount. I can guess this will need PHP, SQL and jQuery to pull off. Problem is I have no idea where to begin. I’ve created already a PHP script to add to my Like’s for a particular image by giving the image ID. I created already a jQuery post button which posts to the PHP and likes the image. The thing I’m stuck on is updating the page to reflect the like.

For starters, I think the code I made to do this so far is completely disgusting lol.

Here is all my code so far.
PHP to output the Likes count and Like button, plus code for addition. $info is the array for the result of my whole image files table:

Echo "<b>Likes:</b> ".$info['likes'] . "</span>";
Echo '<script src="http://code.jquery.com/jquery-latest.js"></script><script     type="text/javascript">function test() {$.post("http://stormstorm.com/like.php?   id='.$info['fileid'].'")</script>';
Echo '<br /><img onClick="test();" src="img/like.jpg"></p>';

The PHP for the like incremented in like.php:

$id = $_GET['id'];
mysql_query("UPDATE files SET likes=likes+1 WHERE fileid=".$id) or die(mysql_error());

The PHP for the liking works fine, I’m happy with that. But the thing to show the liking just sucks badly I think. Thing is I have a list.php which will print the contents of the database one after the other to print all the image listed. So it will print the same replica of the script over and over, typically hard coding the current image ID into the posting. I’m pretty new to this but feel this code sucks, plus it doesn’t update the images section.

I was thinking to use Javascript to simply get the Likes element and ++ it but, then it hit me. My list will have over 100+ of these same elements. You can probably tell I might be approaching this the wrong way, and I hope someone can help me out with this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:33:35+00:00Added an answer on May 30, 2026 at 8:33 pm

    It looks like you have the general idea down, just a crude implementation of it.

    You may want to designate the counter element for each image and update the inner content after the button is pressed…

    <img src="xxx.jpg">
    <p>
        <a href="javascript:test({image_id});">Like</a> <span id="{image_id}_count">150</span>
    </p>
    

    where the {image_id} is obviously unique to each image. Pass that to test({image_id}) and then update the html of the count total on success…

    function test(id)
    {
        $.ajax({
            url: 'http://stormstorm.com/like.php',
            method: 'get',
            data: {id: id},
            dataType: json,
            success: function(data)
            {
                 $('#' + id + '_count').html(data.total);
            }
        });
    }
    

    in your php you would do exactly what you did except return a json encoded array back to the js for update…

    $id = mysql_real_escape_string($_GET['id']);
    mysql_query("UPDATE files SET likes=likes+1 WHERE fileid=".$id);
    if(mysql_affected_rows() > 0)
    {
        $sql = mysql_fetch_assoc(mysql_query("SELECT `likes` FROM `files` WHERE `fileid` = ".$id));
    
        echo json_encode(array('total' => $sql[0]['likes']));
    }
    

    Keep in mind this is a VERY POOR implementation of this. The real system should definitely be one that does not allow people to just repeatedly click the button over and over again to increment something for the hell of it. According to your needs, of course, you should limit it by login and even record user information relative to the file they’re liking and not just increment a number in the database.
    So you would have a relational table that stores information for each like. That way you can query the database to make sure a user has not already liked the file before incrementing the number.

    Hope that makes sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
This could be a duplicate question, but I have no idea what search terms
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.