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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:16:10+00:00 2026-05-26T08:16:10+00:00

So I have my blog set up to pull posts from my database in

  • 0

So I have my blog set up to pull posts from my database in a loop. Each post (#post_) is coupled with a pair of radio buttons. When a radio button is selected, ajax sends the value to check.php where the values are put in my database. The returned html is then displayed in #Message_.

I want to make it so that ONLY when the Like radio button is selected, the div (#Message_) will appear OVER the top right corner of that post’s div.

This is the code I currently have which displays the #Message when any radio button is selected but displays it only underneath the #post.

Calling the loop:

<div id="content">

<form name="myform" action="" method="post">
        <legend>Posts</legend>

<?php
$data = mysql_query("SELECT * FROM Posts");
while($row = mysql_fetch_array( $data )){
?>

The jQuery itself, sitting inside the loop:

<script type="text/javascript">
$(document).ready(function() {

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

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

    });

});
</script>

Display the posts inside the loop:

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

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

End the loop:

<?php 
} 
?>

</div>
  • 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-26T08:16:11+00:00Added an answer on May 26, 2026 at 8:16 am

    not tested but you can figure out what I’ve done here:

    <script type="text/javascript">
    $(document).ready(function() {
    
        $("input[name*='pref_<?php echo $row['postID']; ?>']").click(function() {
            var postID = <?php echo $row['postID']; ?>;
            var value = $(this).val();
            var likeDislike = $(this).id().toString().replace(/(.*)_(.*)/,'$1'); //get 'like or dislike'
            var userID = <?php echo $current_user->ID; ?>;
    
            $.ajax({
                url: 'check.php',
                type: 'POST',
                data: 'userID=' + userID + '&postID=' + postID + '&value=' + value,
                success: function(result) {
                    if (likeDislike == 'like') { 
                        //do like stuff
                        //move the message element into the post at the top, use CSS like float:right or text-align:right etc. to position it to the right
                        $('#Message_<?php echo $row['postID']; ?>').prependTo('#'+postID);
                    }
                    else if (likeDislike == 'dislike') { 
                        //do dislike stuff
                        $('#Message_<?php echo $row['postID']; ?>').html('').html(result);
                    }
                }
            });
    
        });
    
    });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have been using SimplePie on our Magento install to pull our blog posts
I have a daily quote that I post on my wordpress blog each and
Lets say you have a two models with blog posts and comments set up
I have the following set-up. BlogPosts BlogToCategory Category One blog post can have many
I'm working on a blog application in Django. Naturally, I have models set up
I have a blog that has a redirect loop, and I can't understand htaccess
I have a blog on something.wordpress.com , I simply want one post to ALWAYS
I'm using ASP.net and an SQL database. I have a blog like system where
I have a Wordpress blog set up to display comments as Anonymous User by
I have adsense for content set up for my site running on my blog.

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.