[eluser]comyou[/eluser]
Hello all,
I don't know if this is possible because I've tried but keep getting errors.
Basically my view file needs some information:
my actual function needs more than these but this is just an example.
$username
$email
$role
My function needs to query a table first '
agents'
and pull the data from '
id', 'user_id' and '
role'.
I then need to query a second table 'users'
and pull the data '
email' and '
username' where '
id' is equal to '
user_id' from the first table.
I tried having 2 queries in the function but was getting errors.
Any ideas? Thanks.
CODE SNIPPETS
controller
Code:
function index() {
$query_freeagent = $this->get('id')->result_array();
foreach($query_freeagent as $row) :
$user_id = $row->user_id;
$data = array (
$query_user = $this->get_where($user_id),
);
endforeach;
$data = array (
'freeagent_records' => $query_freeagent,
'user_records' =>$query_user,
);
$this->load->view('freeagents/index', $data);
}
function get($order_by) {
$table = "freeagents";
$this->db->order_by($order_by, 'desc');
$query=$this->db->get($table);
return $query;
}
function get_where($id) {
$table = "users";
$this->db->where("id", $id);
$query=$this->db->get($table);
return $query;
}
view file
Code:
<ul id="the-articles" class="-list">
<?php foreach($freeagent_records as $row):
$user_id = $row['user_id'];
$gt= $row['gamertag'];
$console = $row['console'];
$role = $row['role'];
$game = $row['game'];
$twitter = $row['twitter'];
foreach($user_records as $row_2):
$user_id = $row_2->user_id;
?>
<li>
<h3><?php echo $gt; ?> </h3>
<span class="meta">
ID: <b><?php echo $user_id; ?></b>
Console: <b><?php echo $console; ?></b>
Role: <b><?php echo $role; ?></b>
Game: <b><?php echo $game; ?> </b>
</span>
</li>
<?php endforeach;
endforeach; ?>
</ul>