Welcome Guest, Not a member yet? Register   Sign In
how to show url slug by id
#1

[eluser]Unknown[/eluser]
hallo,
i newbie in codeigniter
and i want to display slug by id.

but its not working.

this is code in controller

function view($slug)
{
$this->data['halaman'] = $this->mhalaman->get_profil($slug);

if (empty($data['halaman'])) {
show_404();
}

$data['title'] = $data['halaman']['judul'];
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('mahasiswa/profil/sejarah', $this->data, true);
$this->load->view('template/wrapper/admin/wrapper_ukm',$this->data);
}

this is code in modal

function get_profil($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get($this->tbl_halaman);
return $query->result_array();
}

$query = $this->db->get_where($this->tbl_halaman, array('slug'=>$slug));
return $query->row_array();
}
this is code in view header

<div class="section ui dropdown link item">
<span class="count">Profil</span>
<div class="menu">
&lt;?php foreach ($halaman as $dt): ?&gt;
<div class="item">
<a href="profil/&lt;?php echo $dt['slug'] ?&gt;">&lt;?php echo $dt['judul'] ?&gt;</a>

</div>
&lt;?php endforeach ?&gt;

</div>
</div>

and this is code view content

<div id="content" class="clearfix">
&lt;?php foreach ($halaman as $dt): ?&gt;

<h2>&lt;?php echo $dt['judul'] ?&gt;</h2>
<p>&lt;?php echo $dt['content'] ?&gt;</p>

&lt;?php endforeach ?&gt;

please help me what to do. thank you.
#2

[eluser]Tpojka[/eluser]
Fix your post. Wrap your code in propper tag or link it from pastebin or similar service.
How is now, it is unreadable.
#3

[eluser]Karman de Lange[/eluser]
You not saying what the error is, but quick look at the code (that is very difficult to read)

You return return $query->row_array(); or return $query->result_array(); in same function.. The one will return single row which you should not foreach, the other returns multiple row .





Theme © iAndrew 2016 - Forum software by © MyBB