1

I use 2 tables. First one of the table is Department. I want to show Departments to in User's Profile Page. The user can edit Department in Profile Page. But firstly he can see own department in Profile Page and Profile Edit Page. But There is nothing Department Field in both Profile Page and Profile Edit Page. Maybe Can I do that?

my code is below :

Controller of Profile:

public function index()
    {

        $viewData = new stdClass();
        $viewData->user = $this->db->get("user")->result();
        $viewData->departments = $this->db->get("department")->result();
        $this->lang->load('content', $this->session->userdata('userLang'));
        $this->load->view('profile', $viewData);
    }

My view of Profile:

<aside class="profile-info col-lg-9">
                <section class="panel">
                    <div class="bio-graph-heading">
                        <?php echo $this->lang->line('profile_top_profile_text'); ?>
                    </div>
                    <div class="panel-body bio-graph-info">
                        <h1><?php echo $this->lang->line('profile_text_informations'); ?></h1>
                        <div class="row">
                            <div class="bio-row">
                                <p><span><?php echo $this->lang->line('profile_first_name'); ?></span>: <?php echo $this->session->userdata('people_name'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span><?php echo $this->lang->line('profile_last_name'); ?> </span>: <?php echo $this->session->userdata('people_surname'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Username </span>: <?php echo $this->session->userdata('people_username'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Email </span>: <?php echo $this->session->userdata('people_email'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Language</span>: <?php if ($this->session->userdata('people_lang') == 'en') echo 'English'; else { echo 'Arabic'; } ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Department </span>: <?php if ($this->session->userdata('people_department') == $departments->departmentId) { echo $departments->departmentName;} ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>User Type</span>: <?php if ($this->session->userdata('people_department') == 'en') echo 'English'; else { echo 'Arabic'; } ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>User Status</span>: <?php echo ($this->session->userdata('people_status') == 1) ? "<span class='label label-success''>Active</span>" : "<span class='label label-danger''>Deactive</span>" ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Registered Date </span>: <?php echo $this->session->userdata('people_date'); ?></p>
                            </div>
                            <div class="bio-row">
                                <p><span>Modified Date </span>: <?php echo $this->session->userdata('people_mdate'); ?></p>
                            </div>
                        </div>
                    </div>
                </section>
            </aside>

Department Database:

CREATE TABLE `department` (
  `departmentId` int(11) NOT NULL AUTO_INCREMENT,
  `departmentOffice` int(11) NOT NULL,
  `departmentName` varchar(80) COLLATE utf8_turkish_ci NOT NULL,
  `departmentAuthPerson` int(11) DEFAULT NULL,
  PRIMARY KEY (`departmentId`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_turkish_ci;

Should I do that? Or what can I do for this? Thanks for your helps, big community.

Pradeep
  • 9,667
  • 13
  • 27
  • 34
KhaosCrea
  • 53
  • 6
  • What is the error you are getting? – Pradeep Jul 04 '18 at 10:33
  • It gives no error @pradeep Only, I can not see anything on Department Field in Profile Page. – KhaosCrea Jul 04 '18 at 10:39
  • What is the relationship between the database tables `user` and `department`? Is it `department.departmentAuthPerson` = `user.id`? – am9417 Jul 04 '18 at 10:40
  • No. I just want to show departmentName with session data on Department field in Profile Page. In my codes, I just cannot see anything. Just show blank field of Department. – KhaosCrea Jul 04 '18 at 10:42
  • Here:

    Department : session->userdata('people_department') == $departments->departmentId) { echo $departments->departmentName;} ?>

    @am9417
    – KhaosCrea Jul 04 '18 at 10:49
  • u r using `$this->db->get("department")->result();` it return data in array of object , you should use array notation in your view just print `$viewData->departments` to see the structure return data or just use `$this->db->get("department")->row();` instead – Pradeep Jul 04 '18 at 10:49
  • But how I show it in view page? $this->db->get("department")->row(); ? @pradeep – KhaosCrea Jul 04 '18 at 10:50
  • do it in your controller, just replace `result()` by `row();` its strange u r not getting error, make sure you have enabled error reporting – Pradeep Jul 04 '18 at 10:54
  • It is working best! – KhaosCrea Jul 04 '18 at 10:56

1 Answers1

0

Hope this will help you:

Use row() instead of result() in your index method

public function index()
{
   $viewData = new stdClass();
   $viewData->user = $this->db->get("user")->result();
   $viewData->departments = $this->db->get("department")->row();
   $this->lang->load('content', $this->session->userdata('userLang'));
   $this->load->view('profile', $viewData);
}
Pradeep
  • 9,667
  • 13
  • 27
  • 34
  • if my answer helps you pls don't hesitate to check it as green – Pradeep Jul 04 '18 at 11:07
  • Thank you. It is working best okay. But I want to ask something to you. When I change userDepartment in user table($this->session->userdata('people_department') ), there is nothing field again in Profile Page view. For example userDepartment 1 Admin, it is working but when I change userDepartment 2 there is nothing on Department Field in Profile View. Why? Department table Id 1 Admin 2 Manager 3.. etc. – KhaosCrea Jul 04 '18 at 11:23
  • u should add else part also in your view if `people_department` not matched with department id since your session contains only one user id – Pradeep Jul 04 '18 at 11:28
  • I looked at these, it is matched. But It still field is blank when I change Id 2 by database. – KhaosCrea Jul 04 '18 at 11:33
  • Any problem may be here:

    Department : session->userdata('people_department') == $departments->departmentId) { echo $departments->departmentName;} ?>

    ? Can I do that with InnerJoin?
    – KhaosCrea Jul 04 '18 at 11:35
  • since it is profile page of the user who is logged in so better extract data of that particular user who is logged in by using user id , and yes u should join your table if user has related data in other table – Pradeep Jul 04 '18 at 11:42
  • May you show me how I do that ? I do not know how can i do what you say. – KhaosCrea Jul 04 '18 at 13:10