Reputation: 11
I have some errors on my page. The page is not showing any data from the table.
This is my 1st table structure: Pengguna (User) table :
This the 2nd Table: Karyawan (Employee) table :
And this my model file (User_model.php):
class User_model extends CI_Model
{
function get_user()
{
$result = $this->db->query(
"SELECT * FROM pengguna
LEFT JOIN karyawan ON karyawan.`id.emp` = pengguna.`id.emp`
LEFT JOIN level ON level.`id.level` = pengguna.`id.level`
LEFT JOIN divisi ON divisi.`id.divisi` = pengguna.`id.divisi`");
return $result;
}
}
This my controller file (User.php):
class User extends CI_Controller
{
function __construct()
{
parent::__construct();
//$this->load->model('Auth');
//$this->auth->cek_login();
$this->load->model('User_model');
//$this->User_model->get_user();
}
public function index()
{
if(isset($_SESSION['is_login']) == TRUE)
{
$this->load->view("home/header");
//$this->load->view('user/form_user');
$data['pengguna'] = $this->User_model->get_user();
$this->load->view('user/form_user',$data);
//redirect('user');
$this->load->view("home/footer.php");
}
else
{
$this->load->view('login/form_login');
}
}
}
And last one is The View file on sub folder (user/form_user.php
):
<table>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Username</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
//foreach($pengguna->result() as $row[]) : $count++;
foreach($pengguna->result() as $row) : $count++;
{
?>
<tr>
<td scope="row">
<?php echo $count; ?>
</td>
<td><?php echo $row->'id.level';?></td>
</tr>
<?php
}
endforeach;
?>
</tbody>
</table>
The result show empty data on field ['id.level']
I want to show my ['id.level']
field data
Upvotes: 1
Views: 70
Reputation: 38672
First, use the database field as snake_case. There is nothing wrong with using a dot. But still, it will give errors in the long run.
To fix your issue, you can change the result formatting.
In Model
function get_user()
{
$query = $this->db->query("");
return $query->result_array(); # Add this
}
In HTML
<?php foreach($pengguna as $row) : $count++; ?>
<tr>
<td><?php echo $count; ?></td>
<td><?php echo $row['id.level']; ?></td> # change this
</tr>
<?php endforeach; ?>
Upvotes: 0