Welcome Guest, Not a member yet? Register   Sign In
mysql database
#1

[eluser]Captain_Fluffy_Pants[/eluser]
trying to load mysql database and its not working
controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
function Site(){
parent::_construct();
  }
    function all(){
    $this->load->model('posts');
    $data['rows'] = $this->posts->load_all();
    $this->load->view('pages/view_all', $data);
   }
}
view
Code:
<ol>
&lt;? foreach($row as $row): ?&gt;
<li>&lt;?= $row->title ?&gt;</li>
&lt;? endforeach; ?&gt;
</ol>
model
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Posts extends CI_Model {
    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    function load_all() {
        $query = $this->db->get('posts');
        return $query->result();
    }
}
anyone know what i did wrong?


Messages In This Thread
mysql database - by El Forum - 09-17-2012, 04:02 PM
mysql database - by El Forum - 09-17-2012, 05:46 PM



Theme © iAndrew 2016 - Forum software by © MyBB