• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Separate the categories and give a link for each category

#1
[eluser]BobyKurniawan[/eluser]
I wan't to give the link for my categories in my view . But first pleace chek my table

Code:
fc_artikel
--------------
-idartikel
-judulartikel
-deskripsi
-isiartikel
-tanggalterbit
-slug
-keyword
-username
-flag
-----------------
fc_kategori
------------------
-idkategori
-namakategori
-parentid
-flag
---------------------
fc_artikelkategori
---------------------
-id
-idartikel
-idkategori

it's my controller

Code:
function artikel()
{
$cek = $this->bymodel->cekaman();
if($cek!=null)
{
$x = $this->input->post('cari');
$field= 'judul_artikel';
$config['base_url'] = base_url() . 'admin/artikel/';
$tbl='fc_artikel';
    $config['total_rows'] = $this->bymodel->hitungdata($tbl,$field,$x);
    $config['per_page'] = 5;
    $config['uri_segment'] = 3;
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
    $this->pagination->initialize($config);
$page = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0;  
    $data['artikel'] = $this->bymodel->tampildata3($config['per_page'],$page,$x,$field);
    $data['halaman'] = $this->pagination->create_links();
    $data['include']='admin/list_artikel';
$this->load->view('admin/template/page',$data);
  }
  else
  {
       redirect('login','refresh');
  }
}

my model

Code:
function tampildata3($num, $offset,$x,$field)
{
   $this->db->select('a.idartikel,a.deskripsi,b.slug,a.username,a.isiartikel,a.judul_artikel,a.tanggalterbit,GROUP_CONCAT(b.namakategori) AS namakategori');
   $this->db->from('fc_artikel a');
     $this->db->join('fc_artikelkategori c', 'c.idartikel = a.idartikel','left');
     $this->db->join('fc_kategori b', 'b.idkategori = c.idkategori','left');
   $this->db->limit($num, $offset);
    $this->db->where('a.flag',1);
   $this->db->like($field, $x);
   $this->db->group_by('a.idartikel');
    return $this->db->get()->result();
}

my view
Code:
<table class="table table-hover">          
<tr>
<td>No</td>
<td>Judul</td>
<td>Ketegori</td>
<td>Tanggal Terbit</td>
<td>Penulis</td>
<td>Action</td>
</tr>
&lt;?php
$no = 0;
if(count($artikel)): foreach($artikel as $baris):
$no ++;
  ?&gt;
   <tr>
<td>&lt;?php echo $no; ?&gt;</td>
<td>&lt;?php echo $baris->judul_artikel; ?&gt;</td>
<td>&lt;?php echo $baris->namakategori; ?&gt;</td>
<td>&lt;?php echo $baris->tanggalterbit; ?&gt;</td>
<td>&lt;?php echo $baris->username ; ?&gt;</td>
<td class="action" >
  <a class="glyphicon glyphicon-search">idartikel;?&gt;">View</a>
  <a class="glyphicon glyphicon-pencil">idartikel;?&gt;">Edit</a>
  <a class="glyphicon glyphicon-trash">idartikel;?&gt;">Delete</a>
    </td>
</tr>

&lt;?php endforeach; ?&gt;
&lt;?php else: ?&gt;
  <tr>
   <td colspan="6">Belum ada Data</td>
  </tr>
&lt;?php endif; ?&gt; </table>

Then my views will be generating like this


No Judul Ketegori Tanggal Terbit Penulis Action
1 Judul 1 PHP,Codeigniter 2014-07-17 bossby View Edit Delete
2 Judul k3 2 PHP,HTML 5 2014-07-17 bossby View Edit Delete
3 Judul 2 PHP 2014-07-18 bossby View Edit Delete

as you can see from my view, there are PHP,Codeigniter in first line . So my problem is getting stuck to make a link for each categories and using slug from fc_kategori .

Code:
<a href="base_url/slug">php</a>

#2
[eluser]www.sblog.in[/eluser]
do

Code:
<td><a >namakategori; ?&gt;">&lt;?php echo $baris->namakategori; ?&gt;</a></td>


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.