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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:16:40+00:00 2026-06-01T20:16:40+00:00

I do not know if this is specifically a jquery problem, actually I think

  • 0

I do not know if this is specifically a jquery problem, actually I think it has to mostly do with my logic in the php code.

What Im trying to do is make a voting system that when the user clicks on the vote up or vote down link in the web page, it triggers an ajax call to a php function that first updates the database with with the required value, on success of the database updating the another function is called just to get the required updated html for the that particular post that the user has voted on. (hope I havnt lost you).

The problem I think deals with specifically with this one line of code. When I make the call it only returns the value of $row->beer_down and completly ignores everything else in that line. Funny thing is the same php code to display the html view works perfectly before the ajax function updates it.

echo "<p>Score " . $row->beer_up + $row->beer_down . "</p>";

so here is the code to hope you can help as I have absolutely no idea how to fix this.

here is the view file where it generates the page. This part is the query ajax function.

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

    $(".vote").click(function(){
    var id = $(this).attr("id");
    var name = $(this).attr("name");
    var dataString = 'id='+ id ;
    var parent = $(this);

    if(name=='up') {
       $.ajax({
       type: "POST",
       url:  "http://127.0.0.1/CodeIgniter/blog/add_vote/" + id,
       data: dataString,
       cache: false,

       success: function(html) {
          //parent.html(html);
          $("." + id).load('http://127.0.0.1/CodeIgniter/blog/get_post/' + id).fadeIn("slow");
       }   
       });

    }
    else
    {
       $.ajax({
       type: "POST",
       url: "http://127.0.0.1/CodeIgniter/blog/minus_vote/" + id,
       data: dataString,
       cache: false,

       success: function(html) {
           //parent.html(html);
           $("." + id).load('http://127.0.0.1/CodeIgniter/blog/get_post/' + id).fadeIn("slow");
       }  
       });
    }
    return false;
    });
});
</script>

Here is the html and php part of the page to display the post.

div id="post_container">
<?php //echo $this->table->generate($records); ?>
<?php foreach($records->result() as $row) { ?>
    <?php echo "<div id=\"post\" class=\"" . $row->id . "\">"; ?>
    <h2><?php echo $row->id ?></h2>
    <?php echo "<img src=\"" . base_url() . $dir . $row->account_id . "/" . $row->file_name . "\">" ?>
    <p><?php echo $row->content ?></p>
    <p><?php echo $row->user_name ?> On <?php echo $row->time ?></p>
    <p>Score <?php echo $row->beer_up + $row->beer_down ?></p>
    <?php echo anchor('blog/add_vote/' . $row->id, 'Up Vote', array('class' => 'vote', 'id' => $row->id, 'name' => 'up'));
          echo anchor('blog/minus_vote/' . $row->id, 'Down Vote', array('class' => 'vote', 'id' => $row->id, 'name' => 'down'));
          echo anchor('blog/comments/' . $row->id, 'View Comments');
    ?>
    </div>
    <?php } ?>

here is the function the ajax calls when it is successfull:

function get_post() {   
$this->db->where('id', $this->uri->segment(3));
$records = $this->db->get('post');

$dir = "/uploads/user_uploads/";

foreach($records->result() as $row) {
    echo "<div id=\"post\" class=\"" . $row->id . "\">"; 
    echo "<h2>" . $row->id . "</h2>";
    echo "<img src=\"" . base_url() . $dir . $row->account_id . "/" . $row->file_name . "\">";
    echo "<p>" . $row->content . "</p>";
    echo "<p>" . $row->user_name . " On " . $row->time . "</p>";
    echo "<p>Score " . $row->beer_up + $row->beer_down . "</p>";
    echo "<p>Up score" . $row->beer_up . "beer down" . $row->beer_down . "</p>";
    echo anchor('blog/comments/' . $row->id, 'View Comments');
    echo "</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-06-01T20:16:40+00:00Added an answer on June 1, 2026 at 8:16 pm

    Ok I solved the problem, it seems that I needed to perform the add operation of the two values beer_up and beer_down before I could echo it out. Adding a + in between string concatenation is a no go.

    Thanks for everyone helping out.

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

Sidebar

Related Questions

I know this sort of code is not best practice, but nevertheless in certain
I know this is possible but I'm not really sure where to start. Has
I know this a pretty general question and I'm not looking for code or
I do not know if this is possible, but here goes. And working with
Obviously it's early days, I do not know whether this is information that is
I know this is not programming related, but I have a scenario. Each video
I know this question is not really important.. however I've been wondering: Which of
I know this might sounds not reasonable, and might be a bad design. But
I know this probably really simple but Im not sure what im doing wrong...
I know this is a recurrent/classical topic but I did not found anything that

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.