简体   繁体   中英

User profile in php codeigniter

I am trying to get my user information from "profile_details" table and display in on profile.php view. Here is my Profile.php controller which just display the view for now

<?php
class Profile extends CI_Controller
{
 function __construct()
 {
     parent::__construct();  

 }

function index()
{

    $this->load->view('admin/profile/index');
}
 
}

And here is profile_model.php

<?php
class Profile_model extends CI_Model
{
//table name: profile_details

public function __construct()
{
    parent::__construct();
}


function myProfileDetails($username)
{

$query=$this->db->query('SELECT * FROM profile_details WHERE username = $username');
//$this->db->select('*');
//$query= $this->db->get('customer');
return $query->result();

}

}    

And here is my view (profile) index.php

 <div class="tab-content profile-tab" id="myTabContent">
                    <div class="tab-pane fade show active" id="About" role="tabpanel" aria-labelledby="home-tab">
                        <div class="row">
                          
                           <div class="form-group col-md-6">
                              <label>First Name</label>
                              <span class="form-control"></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Last Name</label>
                              <span class="form-control">3</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Email Id</label>
                              <span class="form-control">f</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Phone</label>
                              <span class="form-control">f</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Sub-Company Name</label>
                              <span class="form-control">g</span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Role</label>
                              <span class="form-control">t</span>
                            </div>
                    </div>
                        
                </div>

And below is profile_details table在此处输入图片说明

Can you please help me how could i get the informations display in my view.

One question: Did you want to fetch all users, or only the authenticate user that you put on view?? Well, Let me explain how to make myProfile (Authenticate User).

Suppose that you haven't inserted your session userdata.

Your model should something like this :

<?php
class Profile_model extends CI_Model
{

public function __construct()
{
    parent::__construct();
    $this->load->database();
}


function myProfileDetails($username)
{

$query=$this->db->query("SELECT first_name, last_name, email, mobile_no, role, company_name, username FROM profile_details WHERE username = '$username'");
return $query->row();

}

}  

After you create your model (taking necessary column to fetch to view), you should call your model inside your controller:

<?php
class Profile extends CI_Controller
{
 function __construct()
 {
     parent::__construct();  
     $this->load->model('Profile_model');

 }

function index()
{

// this is your session:::
    $user_id = 48 // this is your id, roxana
// or
    $username = 'admin';
//::::::::::::::::::::::::
 
    $data['my_profiles'] = $this->Profile_model->myProfileDetails($username); // my_profiles will become your view variable to fetch data basesd on its column name
    $this->load->view('admin/profile/index',$data);
}
 
}

Last, Your view:

<div class="tab-content profile-tab" id="myTabContent">
                    <div class="tab-pane fade show active" id="About" role="tabpanel" aria-labelledby="home-tab">
                        <div class="row">
                          
                           <div class="form-group col-md-6">
                              <label>First Name</label>
                              <span class="form-control"><?= $my_profiles->firstname ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Last Name</label>
                              <span class="form-control"><?= $my_profiles->lastname ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Email Id</label>
                              <span class="form-control"><?= $my_profiles->email ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Phone</label>
                              <span class="form-control"><?= $my_profiles->mobile_no ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Sub-Company Name</label>
                              <span class="form-control"><?= $my_profiles->company_name ?></span>
                            </div>
                            <div class="form-group col-md-6">
                              <label>Role</label>
                              <span class="form-control"><?= $my_profiles->role ?></span>
                            </div>
                    </div>
                        
                </div>

That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM