[eluser]Tom Taila[/eluser]
Ok so ive run into a confusing problem which i cant seem to solve, im basically creating a "vote up" function whereby a user can click a vote up button and this will therefore add the score of the comment which they just voted up (if that makes sense), its kind of like the "like" button on facebook, for example if 50 people on facebook liked something it would say "50 people like this" where as in my case it would say "score = 50".
The problem im having is that when i click on vote up it is incremented by one but once i click on vote up all the scores of all the comments on my page become the incremented value of what i just clicked vote up for. anyway, i cant seem to figure out why i hope you guys can help, heres my code :
Code:
//part of my comment controller
function vote_up() {
$this->load->model('comment_model');
$this->comment_model->vote_up();
redirect('comment');
}
and
Code:
//part of my comment_model model
function vote_up() { //MUST RETRIEVE THE CORRECT ROW AND THEN GET THE COMMENT SCORE, STORE IT AS A VARIABLE, THEN ADD ONE TO IT, THEN UPDATE THE DATABASE WITH ITS NEW SCORE
$query = $this->db->where('id', $this->uri->segment(3));
$comment_row = $this->db->get('comments');
$result = $comment_row->row();
$data = array(
'score' => $result->score + 1
);
$this->db->update('comments', $data);
}
and this is my view
Code:
<?php if(isset($all_comments)){
foreach($all_comments as $row){
echo "<h2>" . $row->user . "</h2>";
echo "<p>" . $row->content . "</p>";
echo "score=" . $row->score . "<br/>";
echo "<a href=" . base_url() . ">id . ">vote up</a><br/>";
echo "<a href=" . base_url() . ">id . ">Delete</a>";
}
}
else {
echo "<h3> No records </h3>";
}
?>
really hope you guys can help this is bugging me so much and i bet its gonna be a simple fix :!