[eluser]davehedgehog[/eluser]
Ah got it, instead of row_array() I needed results_array()
for anyone who may be interested heres the full code~
controller~
Code:
<?php
class Blog extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('blog_model');
}
public function index()
{
$data['blog'] = $this->blog_model->get_blog();
$data['title'] = 'blog archive';
$this->load->view('templates/header');
$this->load->view('templates/blog/blogA');
$this->load->view('blog/index', $data);
$this->load->view('templates/blog/blogB');
$this->load->view('templates/footer');
}
public function view($slug)
{
$data['blog_item']=$this->blog_model->get_blog($slug);
if(empty($data['blog_item']))
{
show_404();
}
$data['title']=$data['blog_item']['title'];
$data['comments'] = $this->blog_model->get_comments($data['blog_item']['id']);
$this->load->view('templates/header',$data);
$this->load->view('templates/blog/blogA');
$this->load->view('blog/view',$data);
$this->load->view('templates/blog/blogB');
$this->load->view('templates/footer',$data);
}
}
?>
the model~
Code:
<?php
class Blog_model extends CI_Model{
function __construct()
{
$this->load->database();
}
function get_blog($slug = FALSE)
{
if($slug === FALSE)
{
$query = $this->db->get('blog');
return $query->result_array();
}
$query = $this->db->get_where('blog',array('slug' => $slug));
return $query->row_array();
}
function set_blog()
{
$this->load->helper('url');
$slug = url_title($this->input->post('title'),'dash',TRUE);
$data = $this->upload->data();
$data = array(
'date' => date("Y-m-d H:i:s"),
'title' => $this->input->post('title'),
'slug' => $slug,
'post' => $this->input->post('post'),
'category' => $this->input->post('category'),
'image' => $filepath = 'uploads/blog/'.$data['file_name']
);
return $this->db->insert('blog',$data);
}
public function get_comments($id)
{
$query = $this->db->get_where('comment',array('entry_id' => $id));
return $query->result_array();
}
}
and view~
Code:
<div id="content">
<table>
<tr><td><h2><?php echo $blog_item['title']?></h2></tr>
<tr><td><img src="<?php echo site_url($blog_item['Image'])?>" /></tr>
<tr><td><h3>Category:<?php echo $blog_item['category']?></h3>
<tr><td>Date:<?php echo $blog_item['date']?></tr>
<tr><td>Post:<?php echo $blog_item['post']?></tr>
</table>
<?php if ($comments): ?><?php foreach($comments as $com): ?>
<table>
<tr><td>Name:<?php echo $com['name']; ?></tr>
<tr><td>Post:<?php echo $com['comment']; ?></tr>
<tr><td>Date:<?php echo $com['date']; ?></tr>
</table><?php endforeach;?><?php else: ?>
<p>
There are no comments for this blog.
</p><?php endif;?>
</div>
Cheers for you help again TheFuzzy0ne =)