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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:20:50+00:00 2026-06-05T17:20:50+00:00

I have am trying to create a simple voting page. There are a few

  • 0

I have am trying to create a simple voting page. There are a few links on each side and when the user click the up arrow the vote is counted and the vote count value is increased. Everything works right now except that when the vote is increased the new value appears on top of the upvote arrow (which makes sense since I am echoing the new value). I have not been able to figure out how to set the updated vote count into the SPAN which should show the vote count.

Here is the code:
HTML

<?php
$sql=mysql_query("SELECT * FROM discussion_links WHERE link_side = 'Michigan'");
while($row = mysql_fetch_array($sql)) {
    $link_id=$row['link_id'];
    $url=$row['link_url'];
    $title=$row['link_title'];
    $source=$row['link_source'];
    $votes=$row['vote_count'];
?> 
<div class="top-links-wrapper">
    <div class="link-info">
        <a class="link-title" href="http://<?php echo $url ?>"><?php echo $title . "</a>"; ?>
        <p class="link-source"><?php echo $source . "</p>" ?>
    </div>
    <div class="link-vote-wrapper">
        <div class="link-votes">
            <span><?php echo $votes; ?></span>
        </div>
        <a href="#" class="vote" id="<?php echo $link_id; ?>" name="up" title="Up vote"></a>
    </div>
</div>
<?php   
    }
?>

I would like to replace the value returned from the PHP function below into the SPAN in the code above.

PHP

<?php
$ip=$_SERVER['REMOTE_ADDR']; 

if($_POST['id']) {
    $id=$_POST['id'];
    $id = mysql_escape_String($id);
    //Verify IP address in Voting_IP table
    $ip_sql=mysql_query("select ip_add from Voting_IP where link_id_fk='$id' and ip_add='$ip'");
    $count=mysql_num_rows($ip_sql);

    if($count==0) {
        // Update Vote.
        $sql = "update discussion_links set vote_count=vote_count+1 where link_id='$id'";
        mysql_query( $sql);
        // Insert IP address and Message Id in Voting_IP table.
        $sql_in = "insert into Voting_IP (link_id_fk,ip_add) values ('$id','$ip')";
        mysql_query( $sql_in);
    }
    else {
        echo "<script>alert('You have already voted');</script>";
    }
    $result=mysql_query("select vote_count from discussion_links where link_id='$id'");
    $row=mysql_fetch_array($result);
    $up_value=$row['vote_count'];
    echo $up_value;
}
?>

This $up_value is the one I would like to replace the current vote count in the HTML.

jQuery

<script type="text/javascript">
    //<![CDATA[
    var $j = jQuery.noConflict();
    $j(function() {
        $j(".vote").click(function() {
            var id = $j(this).attr("id");
            var name = $j(this).attr("name");
            var dataString = 'id='+ id ;
            var parent = $j(this);

            if (name=='up') {
                $j(this).fadeIn(200).html('<img src="dot.gif" />');
                $j.ajax({
                    type: "POST",
                    url: "up_vote.php",
                    data: dataString,
                    cache: false,

                    success: function(html) {
                        parent.html(html);
                    } 
                });
            }
            return false;
        });
    });
    //]]>
</script>

Thanks and any help would be greatly appreciated.

  • 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-05T17:20:52+00:00Added an answer on June 5, 2026 at 5:20 pm

    Assuming that you are returning the appropriate (int) total back in the success function,
    then you should just set the InnerHTML of the span element to that value

    It would be convenient if you were to give each link-votes element a unique ID and use that id to change the InnerHTML of the span element. on ajax success

    Since you are already associating the vote_id with the event handler, then you
    could simply add a prefix to the span id element, and then in the success function,
    call something like this:

           $("#myPrefix"+id).html(html);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple portfolio page. I have a list of thumbs
I am trying to create a simple project with few stateless session beans.I have
I have been trying to create a simple application that will let the user
I am trying to create a simple registration form. I have the following: include('User.datatype.php');
I'm trying to create a simple framed page that reloads each x seconds and
I am trying to create simple user registration form. I have an index.html file
I have been trying to create a simple program with Python which uses OpenCV
I'm trying to create a simple widget to retrieve a users feeds, I have
I am trying to create some simple polygons in openGL3.3. I have 2 types
I have been trying to create an XML using the simplexml library (v2.6.2) http://simple.sourceforge.net/home.php

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.