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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:49:46+00:00 2026-06-09T02:49:46+00:00

I’ve created a like button for my users posts. I’m trying to print out

  • 0

I’ve created a like button for my users posts. I’m trying to print out the amount of likes. At the moment when I click the LIKE button nothing shows beside the like button unless I refresh the page then it shows the amount of like clicks the post has (4).

The problem I face is I have a LIKE_DO.php page that collects the data then sends it to a function which is in another page called function_user.php. Is there anyway I can use Ajax to grab the printed value of likes and how would I go about it? I would really like to just build ontop of the ajax I already have, to insert the data and make a call for the printed likes to save confusion and having to re-write all my code again.

Like Button

echo "<div class='stream_option'><a id='likecontext_".$streamitem_data['streamitem_id']."' style='cursor:pointer;' onClick=\"likestatus(".$streamitem_data['streamitem_id'].",this.id);\">";

CURRENT AJAX

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.PHP

<?php
session_start();
require"rawfeeds_load.php";
if(isset($_POST['streamitem_id'])){

$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 – (With my printed likes that I need to get with ajax)

    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){
        return "(".$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-09T02:49:47+00:00Added an answer on June 9, 2026 at 2:49 am

    Assuming user_core::do_like() adds like data to the database
    and user_core::check_liked() returns number of likes made for that posts.

    (Correct me if I’m wrong)

    if(user_core::do_like($_SESSION['id'],$_POST['streamitem_id'],1)){
    echo $check; // as your user_core::check_liked() function returns number of likes.
    }else{
    echo "<script>alert('Error liking post');</script>";
    }
    

    ALSO :
    Since you are calling say X.php and from X.php you call a function in Y.php. Function in Y.php actually know the value you are looking for.

    Since you are calling X.php values that are echoed in Y.php will not be visible to your script.

    Solution – If you are calling X.php then make Y.php return the values to X.php and echo your values in X.php only.

    +++++++++++++++++++++

    UPDATE As per current latest question:

    Change your $.post handler to

    $.post("../include/like_do.php", { streamitem_id: postid},function(data){
    //see the parameter data in this function. Data contains whatever that you echo in your php file.
    
    $("#yourLikeDisplayDivId").html(data+" Likes");
    
    } );
    
    • 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
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words

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.