These are the 3 tables I have:
ci_comments : comment_id, email, website, body.
ci_relationship : id, comment_id, user_id.
ci_users : user_id, username, email, biography.
The problem is that I'm trying to get data from two tables, one is that of ci_comments that shows all the content of the comments and the other table to get the user_id I mention.
I have this in my edit method in the Comments controller:
// Field Rules
$this->form_validation->set_rules('user_id', 'User ID', 'trim|required');
$this->form_validation->set_rules('body', 'body', 'trim|required');
$this->form_validation->set_rules('status', 'Status', 'required');
if ($this->form_validation->run() == FALSE) {
$data['item'] = $this->Comments_model->get($id);
// AQUI ES DONDE NECESITO AYUDA - No estoy ni seguro si es que debería pasar una variable o no //
// Recuerden que el user_id debe de venir de la table ci_relationship
$data['commentator'] = $this->Comments_model->get_userID($userID);
// /AQUI ES DONDE NECESITO AYUDA //
// Select Comment Author ID
$user_options = array();
$user_options[0] = 'Select Comment Author ID';
$user_list = $this->User_model->get_list();
foreach($user_list as $username){
$user_options[$username->id] = $username->username;
}
$data['user_options'] = $user_options;
// Load template
$this->template->load('admin', 'default', 'comments/edit', $data);
}
Here is the function of the Model that I use to get the content of the current comment:
public function get($id)
{
$this->db->where('id', $id);
$query = $this->db->get('ci_comments');
return $query->row();
}
And here is the function that I am trying to create to get the user_id of the comment:
public function get_userID($userID){
$this->db->select('*');
$this->db->where('user_id', $userID);
$this->db->where('type', $this->type);
$query = $this->db->get('ci_relationship');
return $query->row();
}
Basically I want to show a dropdown where it is supposed to show all the users that have made a comment but not before showing the specific user of the comment:
<div class="form-group">
<?php echo form_label('Author ID', 'user_id'); ?>
<?php echo form_dropdown('user_id', $user_options, $commentator->user_id, array('class' => 'form-control')); ?>
</div>
NOTE: The user_id should be shown in the third parameter $ commentator-> user_id but it shows me null, now if I change it to $ commentator ['user_id] it continues with the same.
I hope I could have explained myself well, otherwise I would not mind editing the question to give more details.