Welcome Guest, Not a member yet? Register   Sign In
how should I show specific data not all data from database?
#1

[eluser]chiquitta[/eluser]
I had met a basic problem that i want to show specific 'account' not all account data from database.

I don't know how to do.
Please help me! And it will be really helpful for me.
Now I write the code like this:

my controllers
Code:
function index()
{
  $data['page_title'] = lang('admins');
  $data['admins']  = $this->auth->get_admin_list();

  $this->load->view($this->config->item('admin_folder').'/admins', $data);
}

my model
Code:
function get_admin_list()
{
  $this->CI->db->select('*');
  $this->CI->db->order_by('image', 'ASC');
  $this->CI->db->order_by('account', 'ASC');
  $result = $this->CI->db->get('admin');
  $result = $result->result();
  
  return $result;
}
my views
Code:
<?php foreach ($admins as $admin):?>
<?php echo $admin->account; ?>
<?php endforeach; ?>

Just like the pic below
If the user's account is chiquitta
when user need to edit her account setting
It should only show her account information not all of the account information from database.
#2

[eluser]PhilTem[/eluser]
You have to make a where-statement in your MySQL query that matches the unique identifier of your current user. That's actually all that needs to be done Wink
#3

[eluser]pickupman[/eluser]
By using an extra parameter to your get_admin_list method, will give you both in one.
Code:
function get_admin_list($id = FALSE)
{
  $this->CI->db->select('*');

  if ($id)
  {
      $this->db->where('id', $id);
  }

  $this->CI->db->order_by('image', 'ASC');
  $this->CI->db->order_by('account', 'ASC');
  $result = $this->CI->db->get('admin');
  $result = $result->result();
  
  return $result;
}

Now if you pass an id to the method, you will get back that specific user. Or if you don't pass anything, you will get all admins. This allows you to set id to FALSE, if a user is a super admin, and be able to view all other admins.
#4

[eluser]chiquitta[/eluser]
Thank you PhilTem and pickupman!

I had try to solve this problem but it still show all account ~
Did I miss something?

my controller
Code:
function index($id = false)
{
  $data['page_title'] = lang('admins');
  $data['admins']  = $this->auth->get_admin_specific($id);
  $this->load->view($this->config->item('admin_folder').'/admins', $data);
}

my model

Code:
function get_admin_specific($id)
{
  $this->CI->db->select('*');
  
  if ($id)
  {
  $this->CI->db->where('id', $id);
  }
  
  $result = $this->CI->db->get('admin');
  $result = $result->result();
  
  return $result;
}

my view

Code:
<?php foreach ($admins as $admin):?>
<?php echo $admin->account; ?>
<?php endforeach; ?>
#5

[eluser]pickupman[/eluser]
Your code looks correct. What we can't see is the value being passed in the URI. Are you passing an integer in your URI, so that it will passed to your model?
#6

[eluser]InsiteFX[/eluser]
Where are you getting the id from?

You need to pass the id through the url for the user you want to display.
#7

[eluser]chiquitta[/eluser]
Thanks pickupman and InsiteFX

I think my problem is that I don't know how to pass the id through the url for the user I want to display.

Now I add a new function to get admin id
But I can't pass the id to function get_admin_specific($id)

what should I do now?

Code:
function get_admin_id($id)
{
  $this->CI->db->select('*');
  $this->CI->db->where('id', $id);
  $result = $this->CI->db->get('admin');
  $result = $result->row();

  return $result;
}
#8

[eluser]InsiteFX[/eluser]
Code:
redirect('controller/function/'.$id, 'refresh');

Code:
function get_admin_id($id)
{
  $this->CI->db->select('*');
  $this->CI->db->where('id', $id);
  $result = $this->CI->db->get('admin');

  $row = $result->row();
  return $row->id;
}




Theme © iAndrew 2016 - Forum software by © MyBB