Welcome Guest, Not a member yet? Register   Sign In
Newbie trying to fetch data and display in table of a logged in user.
#1

[eluser]Unknown[/eluser]
Hi,

I have successfully set up a user login & registration system. However, I am trying to set up a page, which contains a table with data fetch from a mysql database of the specific user only.

The table will show information of the specific user only.

Help!

Thanks in advance!
#2

[eluser]rjsmith[/eluser]
Need a bit more information. Are you trying to grab information from the same table as the user, or some other table with content the user created?
#3

[eluser]InsiteFX[/eluser]
CodeIgniter Users Guide - HTML Table Class

Code from Auth 1.0.6 - by Adam Griffiths.
Code:
// --------------------------------------------------------------------

/**
  * manage()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function manage()
{
  // Grab an array of users from the database
  $data = $this->users->users();

  // Set table headings
  $this->table->set_heading('Username', 'Email', 'Actions');

  foreach($data as $value => $key)
  {
   // Build table actions links
   $actions = anchor("admin/users/edit/".$key['id']."/", "Edit") . anchor("admin/users/delete/".$key['id']."/", "Delete");

   // Add row to table
   $this->table->add_row($key['username'], $key['email'], $actions);
  }

  // Load the Auth specific view
  $this->auth->view('users/manage');
}
#4

[eluser]Unknown[/eluser]
Sorry for providing just a little information.

I guess the idea is basic but I am a newbie and struggling with Codeigniter.

I already set up a login system, with a login page and a member page.

I have a mysql table with 5 column; id, email, password, name, age.

I want to display 4 of the information (except password) of the logged in user into a table in the member page.

Help pls.
#5

[eluser]rjsmith[/eluser]
Code:
//In user_model.php (or whatever you named it if you're using one)
function getUserBy($key, $value){
    $q = $this->db->get_where('users', array($key=>$value));
    $users = FALSE;

    if($q->num_rows() > 0){
        $user = $q->row_array();
    }

    return $user
}

//In your controller
function user($ID){
    $this->load->model('user_model');
    $data['user'] = $this->user_model->getUserBy('id', $ID);

    $this->load->view('my_view', $data);
}

//In your view
<table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Email</th>
            <th>Name</th>
            <th>Age</th>
        </tr>
    </thead>
    <tbody>
         <tr>
            <td>$user['id']</td>
            <td>$user['email']</td>
            <td>$user['name']</td>
            <td>$user['age']</td>
        </tr>
    </tbody>
</table>




Theme © iAndrew 2016 - Forum software by © MyBB