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 8291205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:02:52+00:00 2026-06-08T13:02:52+00:00

I have a like/unlike post on my website, and when I click the like

  • 0

I have a like/unlike post on my website, and when I click the like button I would like the value of check2 to show beside like without me having to refresh the page to see it. Currently I’ll click like and it inserts the data but only shows on a page refresh. I’m hopeless with this kind of stuff.

Here is the code in the order it executes.

Thanks for any help.

POST LIKE

echo "<div class='stream_option'><a id='likecontext_".$streamitem_data['streamitem_id']."' style='cursor:pointer;' onClick=\"likestatus(".$streamitem_data['streamitem_id'].",this.id);\">";
if($checklikes>0){
echo "Unlike";
}else{
echo "Like";
}
echo "</a> ";
$check2 = user_core::print_like_count($streamitem_data['streamitem_id']);
if($check2>0){
echo "(".$check2.")";
}

Ajax Function

function likestatus(postid,contextid){
var obj = document.getElementById(contextid);
if(obj.innerHTML=="Like"){
obj.innerHTML="Unlike";
}else{
obj.innerHTML="Like";
}
$.post("../include/like_do.php", { streamitem_id: postid} );
}

LIKE_DO

$check = user_core::check_liked($_SESSION['id'],$_POST['streamitem_id'],1);

user_core::do_like($_SESSION['id'],$_POST['streamitem_id'],1);

    if($check==0){
    ?>
    <?php
    }else{
    ?>
    <?php
    }
}
else{
echo "<script>alert('Error liking post');</script>";
}
?>

USER_CORE

 function check_liked($id,$streamid,$value){

            $check      =   "SELECT feedback_id FROM streamdata_feedback WHERE feedback_streamid=$streamid AND feedback_userid=$id AND feedback_rating=$value";
            $check1     =    mysql_query($check);
            $check2     =    mysql_num_rows($check1);
        return $check2;
        }

        function print_like_count($streamid){
                $check      =   "SELECT feedback_id FROM streamdata_feedback WHERE feedback_streamid=$streamid AND feedback_rating=1";
                $check1     =    mysql_query($check);
                $check2     =    mysql_num_rows($check1);
                if($check2>0){
                echo "(".$check2.")";
                }
        }
  • 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-06-08T13:02:53+00:00Added an answer on June 8, 2026 at 1:02 pm

    What you’re looking for is an AJAX submission using DHTML to change the value of the likes.

    <script language="javascript">
        $(".likeButton").click(function() {
            $.post("likeProcessor.php", {
                id: $(this).attr('id')
            }, function(data) {
                $("#likeIndicator" + $(this).attr('id')).html(data);
            });
    </script>
    

    Then your likeProcessor script will simply return the number of likes for that item.

    NOTE: This is pseudo-code to give you an idea of what needs to happen. For further info on jQuery and Ajax, RTM at http://www.w3schools.com/jquery/default.asp and http://www.w3schools.com/ajax/default.asp respectively.

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

Sidebar

Related Questions

I have a blog. I like people to login to my website and mark
I have a small site where I would like to give the ability to
So I'm going to explain this with an example. I have a like button
I have strings with space seperated values and I would like to pick up
I have a controller with the codes like this: [AcceptVerbs(POST)] public ActionResult Create(FormCollection collection)
I would like to implement the Login with facebook feature on my website and
Unlike in C++ or Java, whenever I have something like print "Hello " +
So i have a page with a like button under my comments and am
Having some pain with this event, I have some code like this for a
I have following JSON object. {feed:[ {news: {adopted_from:null,user_id:null,description:this is test,id:2} }, {news: {adopted_from:null,user_id:null,description:like unlike

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.