Welcome Guest, Not a member yet? Register   Sign In
need foreach
#1

[eluser]anyamanggar[/eluser]
for view
Code:
<?php foreach ($publication as $itemlist): ?>
<?php echo $itemlist['title'] ?>
<?php endforeach ?>

publication_model
Code:
<?php

class Publication_model extends CI_model{

function __construct()
{
  parent::__construct();
}

function getall(){
  
$this->load->database();
$this->db->order_by('id','asc');
$query = $this->db->get('publication');
return $query->result();
}

function delete($id){
$this->load->database();
$this->db->delete('publication', array('id' => $id));
}

   function retrieve() {    
   $this->load->database();
   $this->db->order_by("id", "asc");
   $query = $this->db->get('publication');
   return $query;
   }

function create() {
        $data = array(
            'title' => $this->input->post('title'),
            'link' => $this->input->post('link'));
       $this->db->insert('publication',$data);
    }

  function findById($id) {
        $this->db->where('id', $id);
       $query = $this->db->get('publication');
        return $query->row_array();
    }

function update(){
$this->load->database();
$data = array(
'title'=>$this->input->post('title'),
'link'=>$this->input->post('link'));
$this->db->where('id',$this->input->post('id'));
$this->db->update('publication',$data);
}


// ini untuk setting database list berita depan
// end of class model
}

controller
Code:
$this->load->model('publication_model');
       $query = $this->publication_model->retrieve();
       $data['publication'] = $query;

please help me, i have try with my code but the result is errroorr

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: title

Filename: template/home_view.php

Line Number: 40
please help me//
#2

[eluser]InsiteFX[/eluser]
Try this
Code:
<?php foreach ($publication as $itemlist): ?>
<?php echo $itemlist->title; ?>
<?php endforeach ?>
#3

[eluser]anyamanggar[/eluser]
still eror

Code:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: template/home_view.php

Line Number: 41
#4

[eluser]anyamanggar[/eluser]
fixt.. tq
#5

[eluser]JamieBarton[/eluser]
[quote author="InsiteFX" date="1341817383"]Try this
Code:
<?php foreach ($publication as $itemlist): ?>
<?php echo $itemlist->title; ?>
<?php endforeach ?>
[/quote]

How about?

Code:
<?php foreach ($publication->result() as $itemlist): ?>
<?php echo $itemlist->title; ?>
<?php endforeach ?>




Theme © iAndrew 2016 - Forum software by © MyBB