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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:52:36+00:00 2026-05-27T16:52:36+00:00

how can I get the variable value I need, I have selected comments and

  • 0

how can I get the variable value I need, I have selected comments and like values through MySQL and have created a like button, but when I click like, it adds the like to the last selected/posted variable value, so it likes the last comment generated. How to I get it to like the one I wanted and not the last selected?

Example:

I have comments with id’s (1,2,3) when generated it orders them in that order (1,2,3) when I like comment with id=2 it likes comment 3 because it was last generated so the varible id has a value of 3 at the time I liked comment 2.

I don’t make any sense, I hope you guys get it, please help???

  • 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-27T16:52:37+00:00Added an answer on May 27, 2026 at 4:52 pm

    note.php

    //-------- WHILE LOOP FOR GETTING NOTE COMMENTS -------
    
    $commentsList = array();
    
    $query = mysql_query("SELECT * FROM note_comments WHERE note_id='$note_id'");
    while (($row = mysql_fetch_assoc($query)) != false) {
        $commentsList[] = array(
            'comId' => $row['id'],
            'comment' => $row['comment'],
            'com_likes' => $row['likes'],
            'com_likers' => $row['likers']
        );
    }
    

    note.php (body):

            <div id="noteComments">
            <h2>Comments</h2>
            <?php 
            $commentL = $commentsList;
            if (count($commentL) == 0) {
                echo 'Sorry, there are no comments.';
            } else {
                echo '<ul style="list-style:none;">';
                foreach($commentL as $comment) {
                    echo '<li><p>', $comment['comment'], '</p><p><a style="background-color:#3b3c3b; color:#fff;
                    text-decoration:none; padding: 1 5 1 5; border-radius:5px; border: 1px solid black; " href="#" onclick="like_add(', $comment['comId'] ,');">Like</a><span id="comment_', $comment['comId'] ,'_likes">', $comment['com_likes'] , '</span> like this</p></li>';
                }
                echo '</ul>';
            }
            ?>
            </div><!-- end noteComments -->
    

    like.js

    function like_add(comId) {
    $.post('ajax/like_add.php', {comId:comId}, function(data) {
        if (data == 'success') {
            like_get(comId);
        } else {
            alert(data);
        }
    }); 
    }
    
    function like_get(comId) {
    $.post('ajax/like_get.php', {comId:comId}, function(data) {
        $('#comment_'+comId+'_likes').text(data);
    });
    }
    

    like_add.php

    <?php
    include_once("../scripts/checkuserlog.php");
    include '../functions/like.php';
    if (isset($_POST['comId']) && comment_exists($_POST['comId'])) {
    $comId = $_POST['comId'];
    add_like($comId);
    }
    ?>
    

    like_get.php

    <?php
    include '../scripts/checkuserlog.php';
    include '../functions/like.php';
    if (isset($_POST['comId']) && comment_exists($_POST['comId'])) {
    echo like_count($_POST['comId']);
    }
    ?>
    

    like.php

    <?php
    function comment_exists($comId) {
    $comId = (int)$comId;
    return (mysql_result(mysql_query("SELECT COUNT('id') FROM note_comments WHERE id=$comId"), 0) == 0) ? false : true;
    }
    
    function like_count($comId) {
    $comId = (int)$comId;
    return (int)mysql_result(mysql_query("SELECT likes FROM note_comments WHERE id=$comId"), 0, 'likes');
    }
    function add_like($comId) {
    $comId = (int)$comId;
    $visitor = $_SESSION['id'];
    $com_likers = "";
    $query = mysql_query("SELECT likes, likers FROM note_comments WHERE id='$comId'");
    while (($row = mysql_fetch_array($query)) != false) {
    
            $com_likes = $row['likes'];
            $com_likers = $row['likers'];
    } 
    $thisComlikers = explode(",", $com_likers);
    if (!in_array($visitor, $thisComlikers)) {
        if ($com_likers != "") { $com_likers = "$com_likers,$visitor"; } else { $com_likers = "$visitor"; }
    
    mysql_query("UPDATE note_comments SET likes = likes + 1 WHERE id=$comId")or die (mysql_error());
    mysql_query("UPDATE note_comments SET likers =$com_likers WHERE id=$comId")or die (mysql_error());
    echo 'success';
    } else {
        echo 'You have already liked this!';
    }
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me why I get the null value for activationLink variable in
How can I get the variable My.Application.Info.Version.ToString to populate in the comments section? Dim
How can I get Environnment variables and if something is missing, set the value?
With the environment variable %allusersprofile% I can get the directory where common settings are
Given this variable in tcsh: set i = ~/foo/bar.c how can I get just
I can't find a correct way to get the environment variable for the appdata
can't seem to get the syntax right in order to pass the AttID variable.
I have a variable for the background-image attribute of an element that I need
I have a variable results ($result) of several rows of data or object like
I have a table of values (actually written in LaTeX markup) and I can

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.