Active Inactive user status

In this tutorial, we are going to learn how to create active inactive user status.


Step 1 : Open your dashboard view file and there we will write the code that if the status of the user is one then it becomes active or else it becomes inactive.


<?php if($users->status == 1){ ?>

    <a href="#" class="btn btn-success">Active</a>

<?php }else{ ?>

     <a href="#" class="btn btn-danger">Inactive</a>

<?php } ?>


Now, Create a link of status button for update user status and then pass user id and status with link. So that we will update the user status.

<a href="<?php echo base_url(); ?>dashboard/update_status/<?php echo $users->id; ?>/<?php echo $users->status; ?>" class="btn btn-success">Active</a>


Step 2 : Open your dashboard model, and create update_status function, so that i can send the user Id and status to the model to update the user's status.


public function update_status($id,$status)

	//send id and status to the model to update the status
		$this->session->set_flashdata('msg','User status has been updated successfully!');
		$this->session->set_flashdata('msg','User status has not been updated successfully!');
	return redirect('dashboard');


Step 3 :  In dashboard model, we will create update_status_model function. So that we will update the user status in database with the help of user ID and Status.


public function update_status_model($id,$status)
	//here we will change the value of the status that if we get the value one of the status then zero is updated in database otherwise one.

	if($status == 1)
		$sval = 0;
		$sval = 1;

	// update status value in database 
	$data = array( 'status' => $sval );


	return $this->db->update('userdata',$data);


Result :

Source Code:

Codeigniter tutorial for beginners

In this project. We are providing you, how to create small project in Codeign....

Source Code