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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:30+00:00 2026-05-26T10:39:30+00:00

I have two buttons (liked/disliked) which are actually images attached to an href tag

  • 0

I have two “buttons” (liked/disliked) which are actually images attached to an href tag that when the user clicks, values are sent to my database. #Messages displays the output of check.php which simply returns the values. The jQuery code sits inside a loop along with the html for the buttons.

The weird thing is that my code works for only the Like button and only if the dislike button is removed from my code. The dislike button by itself (like button removed from code) doesn’t work at all and if both buttons are coded, neither button works.

Also, the #like is supposed to display before the #dislike, but on my page #dislike appears to the left of #like, which is not what is supposed to happen (it should appear to the right of #like). Any ideas for that?

Begin loop:

<?php
$data = mysql_query("SELECT * FROM Contests");

while($row = mysql_fetch_array( $data )){
$query = mysql_query("SELECT * FROM userContests WHERE userID='$userID' AND contestID='$row[contestID]';") or die(mysql_error()); 
$checked = mysql_fetch_assoc($query);
?>

My jQuery (if I remove #dislike, then #like works. If I remove #like, #dislike doesn’t work. When both are present, neither works):

<script type="text/javascript">
$(document).ready(function() {
    var checked = <?php echo $checked['value']; ?>;
    var postID = <?php echo $row['postID']; ?>;
    var userID = <?php echo $current_user->ID; ?>;

    if (checked == 1) {
        $('#post_<?php echo $row['postID']; ?>').addClass('like'); 
    } else if (checked == 0) {
        $('#post_<?php echo $row['postID']; ?>').addClass('dislike'); 
    }

    $('#like_<?php echo $row['postID']; ?>').click(function(liked) {

        $.ajax({
            url: 'check.php',
            type: 'POST',
            data: 'userID=' + userID + '&postID=' + postID + '&value=' + '1',
            success: function(result) {
                $('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
            }
        });

        $('#post_<?php echo $row['postID']; ?>').removeClass('dislike').addClass('like');
        if (showLikes.attr('checked')) {
            $('#post_<?php echo $row['postID']; ?>').toggle();
        }
    });

    $('#dislike_<?php echo $row['postID']; ?>').click(function(disliked) {

        $.ajax({
            url: 'check.php',
            type: 'POST',
            data: 'userID=' + userID + '&postID=' + postID + '&value=' + '0',
            success: function(result) {
                $('#Message_<?php echo $row['postID']; ?>').html('').html(result).prependTo('#post_<?php echo $row['postID']; ?>');
            }

        $('#post_<?php echo $row['postID']; ?>').removeClass('like').addClass('dislike'); 
        if (showDislikes.attr('checked')) {
            $('#post_<?php echo $row['postID']; ?>').toggle();
        }
    });

My HTML:

<div id="post_<?php echo $row['postID']; ?>" class="post">
<div id="post_<?php echo $row['postID']; ?>_inside">
    <div>
        <a id="like_<?php echo $row['postID']; ?>" class="like" href="#"><span></span></a>
    </div>
    <div>
        <a id="dislike_<?php echo $row['postID']; ?>" class="dislike" href="#"><span></span></a>
    </div>
    <b><?php echo $row['Title']; ?></b><br>
    Expires: <?php echo $row['Exp']; ?><br>
    <ul id="listM"></ul> 
</div>
</div>
<div id="Message_<?php echo $row['postID']; ?>" class="reminder"></div>

End loop:

<?php 
} 
?>

My CSS:

a.like {
float: right;
background: url(images/entered.png) no-repeat top center;
height: 30px;
width: 28px;
}

a.like:active {
float: right;
background: url(images/entered.png) no-repeat bottom center;
height: 30px;
width: 28px;
}

a.dislike {
float: right;
background: url(images/not-interested.png) no-repeat top center;
height: 30px;
width: 28px;
}

a.dislike:active {
float: right;
background: url(images/not-interested.png) no-repeat bottom center;
height: 30px;
width: 28px;
}

So what could possibly be going on? If #like works without #dislike, then why won’t #dislike work without #like?

  • 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-26T10:39:31+00:00Added an answer on May 26, 2026 at 10:39 am

    I manage to solve the problem by inserting the value named value sent through ajax inside a variable.

    I don’t know why it doesn’t work when hard-coded but there you go.

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

Sidebar

Related Questions

I have two buttons, which the user can click and will open a FileDiagloag
I have two buttons which call the same function. That functions signature is -
I have two buttons that moves a movieclip up/down the Y-axis. How do I
I have two toggle buttons that I want to link together so that pressing
Suppose I have two buttons that are ivar outlets. One is called Blue and
I have a program which plays two sounds. I want the user to know
I have two buttons What I would like to do is inside button1_click() which
I have two buttons that have assigned two functions, one by a broad selection:
I would like to write a Web Application that would have two buttons and
I have two buttons on my page: <a class=button accessLink id=loginLink data-disabled=false data-href=/MyAccount/Access/Login title=Login>Login</a>

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.