-
wolfgang1983
Senior Member
-
Posts: 627
Threads: 271
Joined: Oct 2014
Reputation:
7
12-27-2015, 03:25 AM
(This post was last modified: 12-27-2015, 02:29 PM by wolfgang1983.)
On my forum I am learning to make I have made a reputation vote model.
I would like to know. When forum_user_reputation get's to 0 from been voted down $this->input->post('vote_down') to it then it should stop there.
Currently if the question gets down voted still the forum_user_reputation will go into negative -2 but I need to make it stop at 0
How could I make suitable changes to my function update_forum_question()
PHP Code: public function update_forum_question() { $current_votes = $this->get_question_reputation();
if ($this->input->post('vote_up') == TRUE) {
$sum_total = $current_votes + $this->input->post('vote_up'); $data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_question_id', '1'); $this->db->where('forum_user_id', '1'); $this->db->update('forum_questions', $data);
$forum_user_reputation = $this->get_forum_user_reputation();
$forum_reputation = $forum_user_reputation + 5;
$data = array( 'forum_reputation' => $forum_reputation );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
} elseif ($this->input->post('vote_down') == TRUE) {
$sum_total = $current_votes - $this->input->post('vote_down');
$data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_user_id', '1'); $this->db->where('forum_question_id', '1'); $this->db->update('forum_questions', $data);
$form_votes = $current_votes - 2;
$data = array( 'forum_reputation' => (int)$form_votes );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
} }
Thanks for you advice
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
-
InsiteFX
Super Moderator
-
Posts: 6,331
Threads: 291
Joined: Oct 2014
Reputation:
235
(12-27-2015, 03:25 AM)wolfgang1983 Wrote: On my forum I am learning to make I have made a reputation vote model.
I would like to know. When forum_user_reputation get's to 0 from been voted down $this->input->post('vote_down') to it then it should stop there.
Currently if the question gets down voted still the forum_user_reputation will go into negative -2 but I need to make it stop at 0
How could I make suitable changes to my function update_forum_question()
PHP Code: public function update_forum_question() { $current_votes = $this->get_question_reputation();
if ($this->input->post('vote_up') == TRUE) {
$sum_total = $current_votes + $this->input->post('vote_up'); $data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_question_id', '1'); $this->db->where('forum_user_id', '1'); $this->db->update('forum_questions', $data);
$forum_user_reputation = $this->get_forum_user_reputation();
$forum_reputation = $forum_user_reputation + 5;
$data = array( 'forum_reputation' => $forum_reputation );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
} elseif ($this->input->post('vote_down') == TRUE) {
$sum_total = $current_votes - $this->input->post('vote_down');
$data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_user_id', '1'); $this->db->where('forum_question_id', '1'); $this->db->update('forum_questions', $data);
$form_votes = $current_votes - 2;
$data = array( 'forum_reputation' => (int)$form_votes );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
} }
Thanks for you advice
Try this:
PHP Code: public function update_forum_question() { $current_votes = $this->get_question_reputation();
if ($this->input->post('vote_up') == TRUE) { $sum_total = $current_votes + $this->input->post('vote_up');
$data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_question_id', '1'); $this->db->where('forum_user_id', '1'); $this->db->update('forum_questions', $data);
$forum_user_reputation = $this->get_forum_user_reputation();
$forum_reputation = $forum_user_reputation + 5;
$data = array( 'forum_reputation' => $forum_reputation );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
} elseif ($this->input->post('vote_down') == TRUE) {
$sum_total = $current_votes - $this->input->post('vote_down');
// check to see if vote_down is less than 0 or equals 0 if ($sum_total <= 0) { $sum_total = 0; }
$data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_user_id', '1'); $this->db->where('forum_question_id', '1'); $this->db->update('forum_questions', $data);
$form_votes = $current_votes - 2;
$data = array( 'forum_reputation' => (int)$form_votes );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
} }
Not tested.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
wolfgang1983
Senior Member
-
Posts: 627
Threads: 271
Joined: Oct 2014
Reputation:
7
Thank you for that advice
Where it updates the user votes I added it just above it and works fine
PHP Code: public function update_forum_question() {
$current_votes = $this->get_question_reputation();
if ($this->input->post('vote_up') == TRUE) {
$sum_total = $current_votes + $this->input->post('vote_up');
$data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_question_id', '1'); $this->db->where('forum_user_id', '1'); $this->db->update('forum_questions', $data);
$forum_user_reputation = $this->get_forum_user_reputation();
$forum_reputation = $forum_user_reputation + 5;
$data = array( 'forum_reputation' => $forum_reputation );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
}
elseif ($this->input->post('vote_down') == TRUE)
{
$sum_total = $current_votes - $this->input->post('vote_down');
$data = array( 'forum_question_reputation' => $sum_total );
$this->db->where('forum_user_id', '1'); $this->db->where('forum_question_id', '1'); $this->db->update('forum_questions', $data);
$forum_votes = $current_votes - 2;
// check to see if vote_down is less than 0 or equals 0 if ($forum_votes <= 0) { $forum_votes = 0; }
$data = array( 'forum_reputation' => (int)$forum_votes );
$this->db->where('forum_user_id', '1'); $this->db->update('forum_user', $data);
}
}
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!
|