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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:50:39+00:00 2026-05-25T22:50:39+00:00

So I have a loop going that pulls posts onto the page. Each post

  • 0

So I have a loop going that pulls posts onto the page. Each post has a pair of radio buttons (like/dislike) that when pressed sends their values to my database. The page is set up to pull that information on pageload so the radio buttons are autoselected to their previous state as the user decided.

Now I want a pair of checkboxes (master controls) that show/hide all disliked and all liked posts. Problem is I have no idea how to do this… I know the logic is such that

#show_likes.click (function(){If $Mysql_value = 1  {toggle} else {ignore} });
#show_dislikes.click (function(){If $Mysql_value = 1  {toggle} else {ignore} });

This is what I already have in place:

<?php global $current_user;
get_currentuserinfo();
$userID = $current_user->ID;
?>

<div id="content">

<form name="myform" action="check.php" method="post">
    <fieldset>
        <legend>Master Controls</legend>
    <div class="left">
            <p><input id="show_likes" name="show_likes" type="checkbox" value="1" onclick="toggleLayer(this.form);" />      
    <label for="b1">Hide Likes:</label></p>
</div>
<div class="right">
    <p><input id="show_dislikes" name="show_dislikes" type="checkbox" value="1" onclick="toggleLayer(this.form);" />
    <label for="b1">Hide Disikes:</label></p>
</div>
    </fieldset>
<br><br>

   <fieldset>
        <legend>Posts</legend>

<?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);
?>

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

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

    $("input[name*='pref_<?php echo $row['contestID']; ?>']").click(function() {
        var contestID = <?php echo $row['contestID']; ?>;
        var value = $(this).val();
        var userID = <?php echo $current_user->ID; ?>;

        $.ajax({
            url: '../wp-content/themes/MC/check.php',
            type: 'POST',
            data: 'userID=' + userID + '&contestID=' + contestID + '&value=' + value,
            success: function(result) {
                $('#Message_<?php echo $row['contestID']; ?>').html('').html(result);
            }
        });
        if (value = 1) {
            $('#contest_<?php echo $row['contestID']; ?>').removeClass('dislike').addClass('like'); 
        } else if (value = 0) {
            $('#contest_<?php echo $row['contestID']; ?>').removeClass('like').addClass('dislike'); 
        }
    });

    $("input[name*='show_likes']").click(function() {
        if ($('#contest_<?php echo $row['contestID']; ?>').is('.like')) {
            $('#contest_<?php echo $row['contestID']; ?>').toggle();
        }
    });
});
</script>


<div id="contest_<?php echo $row['contestID']; ?>" class="post">
<div id="contest_<?php echo $row['contestID']; ?>_inside">
    <b><?php echo $row['Title']; ?></b><br>
    Expires: <?php echo $row['Exp']; ?><br>
    <ul id="listM"></ul>

    <form id="form_<?php echo $row['contestID']; ?>" action="/">  
        <fieldset> 
            <div class="left"><p><input id="like_<?php echo $row['contestID']; ?>" type="radio" name="pref_<?php echo $row['contestID']; ?>" value="1"<?php if ($checked['value'] == "1") echo " checked"; ?> />
            <label for="like_<?php echo $row['contestID']; ?>">Like</label></p></div>
            <div class="right"><p><input id="dislike_<?php echo $row['contestID']; ?>" type="radio" name="pref_<?php echo $row['contestID']; ?>" value="0"<? if ($checked['value'] == "0") echo " checked"; ?> />
            <label for="dislike_<?php echo $row['contestID']; ?>">Dislike</label></p></div>
                <hr />
        </fieldset>  
    </form>  
</div>
</div>
<div id="Message_<?php echo $row['contestID']; ?>"></div>

<?php 
} 
?>

</div>

Can anyone help me go from here?

  • 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-25T22:50:39+00:00Added an answer on May 25, 2026 at 10:50 pm

    Basically what you want to do is label each div containing a post with a class. For example use like and dislike as class names. This way when someone clicks your show_likes button, you can trigger a function which will hide all posts with class dislike and show all posts with class like. Like this for example:

    $('#show_likes').click(function() {
        $('.like').show();
        $('.dislike').hide();
    }
    

    Also be sure that when someone likes or dislike a certain post, you update the class of that post.

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

Sidebar

Related Questions

I have a loop that reads each line in a file using getline() :
I have a loop on page to update an access database that takes 15-20
I have a loop that runs through a variety of websites and I'd like
I have a while loop that is going through and displaying an RSS icon
I have a loop that finds duplicate lines in a .ini file. I can
I have a loop like this: for i=1:no %some calculations fid = fopen('c:\\out.txt','wt'); %write
I have a loop created with each, check this example: $('.foo').each(function(i){ //do stuff });
I have a loop that runs for approx. 25 minutes i.e 1500 seconds. [100
I have an array: var bar = []; I have a for loop going
I seem to have some weird issue going on that I am sure will

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.