database problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: database problem (/showthread.php?tid=26184) |
database problem - El Forum - 01-07-2010 [eluser]LeonardoRaygoza[/eluser] Im having a problem, I set on the database.php the credentials to mY localhost, Im trying to work on mysql, I followed the user-guide. I created a new model, then the function. <?php class Blogmodel extends Model { function Blogmodel { parent::Model(); $this->load->database(); } function get_entries() { $query = $this->db->query(‘Select * from mytable’); } } ?> then I’m calling the model from controller. <?php class Blog extends Controller{ function Blog() { parent::Controller(); } function index() { $this->load->model(‘blog_model’); $data[‘query’] = $this->blog_model->get_entries(); $this->load->view(‘blog_view’, $data); } } ?> this is my view code: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html > <head> <meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /> <title>Leo’s Blog</title> </head> <body> <h1>This is my blog!</h1> <?php foreach($query->result() as $row) { echo $row->id_usuario; echo $row->nombre; echo $row->usuario; echo $row->password; echo $row->email; } ?> </body> </html> database problem - El Forum - 01-07-2010 [eluser]purerj[/eluser] One thing jumped right out when I looked at your code. You named your model "Blogmodel" and you refer to it as "blog_model" in your controller. $this->load->model(‘blog_model’); $data[‘query’] = $this->blog_model->get_entries(); Fix that first. |