• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
database problem

#1
[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”>
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” /&gt;
&lt;title&gt;Leo’s Blog&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<h1>This is my blog!</h1>

&lt;?php
foreach($query->result() as $row)
{
echo $row->id_usuario;
echo $row->nombre;
echo $row->usuario;
echo $row->password;
echo $row->email;
}


?&gt;

&lt;/body&gt;
&lt;/html&gt;

#2
[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. Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.