Project Tutorials
Introduction Directory Structure Project Setup Remove index.php using htaccess Change Default Controller CSS Add in Project Create Login Page Design Validation on Login Login with Database Flashdata on Login Display Username after Login Logout Design Dashboard Page List user data form database Insert Data Flash message show if data inserted Delete data from datebase Edit data from datebase Active Inactive user status Show active users detail on home page Image Upload Edit Image View Image on Home PageActive 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.
eg:
<?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.
eg:
public function update_status($id,$status)
{
$this->load->model('dashboard_model','userdata');
//send id and status to the model to update the status
if($this->userdata->update_status_model($id,$status))
{
$this->session->set_flashdata('msg','User status has been updated successfully!');
$this->session->set_flashdata('msg_class','alert-success');
}
else{
$this->session->set_flashdata('msg','User status has not been updated successfully!');
$this->session->set_flashdata('msg_class','alert-danger');
}
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.
eg:
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;
}
else{
$sval = 1;
}
// update status value in database
$data = array( 'status' => $sval );
$this->db->where('id',$id);
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 CodeSEARCH POST HERE
Support Us
Subscribe My YouTube Channel
Join Our Telegram Channel & Support Eachother
CATEGORIES
INTERVIEW QUESTIONS
POPULAR POSTS
Elevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date