Welcome Guest, Not a member yet? Register   Sign In
[Solved] MY Custom Fourm Vote: Stop forum votes going below 0
#1

(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

Attached Files
.php   Model_forum.php (Size: 1.75 KB / Downloads: 61)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

(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 )
Reply
#3

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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB