CodeIgniter Forums

Full Version: need foreach
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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//

El Forum

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

El Forum

[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

El Forum

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

El Forum

[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 ?>