Welcome Guest, Not a member yet? Register   Sign In
my very simple guesbook doesn't work
#1

[eluser]linderox[/eluser]
I have very strange situation.I have 2 very similar simple scripts, which connect to the database and get data. But one of these doesn't works successfuly, but another doesn't give me anything even errors.
here is working script. Just only Conroller
Code:
<?php

class Testdb extends Controller {

    function Testdb()
    {
        parent::controller();    
    }
    
    function index()
    {    
        //$query = $this->db->query("SELECT name,text,date FROM guestbook")
        $this->db->select();
        $query = $this->db->get('guestbook');
        if ($query->num_rows() > 0)
        {
        foreach ($query->result() as $row)
            {
                echo $row->name;
                echo $row->text;
                echo $row->date;
                echo '<br>';
            }
        }    
    }
    
}
?&gt;

here is doesn't working MVC architecture of that script
Code:
//controller

&lt;?php

class Feedback    extends Controller {

    function Feedback()
    {
        parent::Controller();    
    }
    
    function index()
    {    
        $data['title'] = "guestbook";
        $this->load->database();
        $this->load->model('guestbook');        
        $this->load->helper('form');
        $data['items']=$this->guestbook->getdata();
        $this->load->view('feedback/index', $data);
        
    }
    
}
?&gt;
my model
Code:
&lt;?php

class Guestbook extends Model {

    function Guestbook()
    {
        parent::Model();    
    }
    
    
    function getdata()
        {
            $this->db->select('*')->from('guestbook');
            $query = $this->db->get();
            if ($query->num_rows() > 0)
                {
                    return $query->result_array();
                }
            else
                {
                    return FALSE;
                }
        }
    
}
?&gt;
my view
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Blog Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<h3>My Blogs</h3>  
<div>
<p>
<ul>
&lt;?php foreach($items as $row):?&gt;

<h4>&lt;?=$row['text']?&gt;</h4>
<p>&lt;?=$row['date']?&gt;</p>
<p>Posted by &lt;?=$row['name']?&gt;</p>

&lt;?php endforeach;?&gt;
</ul>

</p>
</div>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]bretticus[/eluser]
Code:
$this->load->model('Guestbook');
$data['items']=$this->Guestbook->getdata();

My guess is that you have a lowercase "g" in "Guestbook." When you load a model, you reference it with the same name as the class.
#3

[eluser]tomcode[/eluser]
Try by replacing
Code:
$this->db->select('*')->from('guestbook');
$query = $this->db->get();

with
Code:
$query = $this->db->get('guestbook');

And check wether You get any entries
Code:
echo $query->num_rows();
#4

[eluser]linderox[/eluser]
yes! i changed from your example to this
Code:
...->select(*)->

where i should check $query->num_rows() in the model or controller?
#5

[eluser]tomcode[/eluser]
[quote author="linderox" date="1237554815"]where i should check $query->num_rows() in the model or controller?[/quote]

Well, that's for testing, put it in the controller...

You could do in the controller :

Code:
$num_rows = $query->num_rows();

$format = 'Found %s entries.';

$data['count_info'] = sprintf($format, $num_rows);

and add in the view :
Code:
<p>&lt;?=$count_info?&gt;</p>
#6

[eluser]linderox[/eluser]
doesn't work too... I don't know how to check where is a problem
Maybe there is a problem with my .htaccess file?
I use view/feedback/index.php file for view
#7

[eluser]linderox[/eluser]
yes! there is a problem with this access type to the view. but how to solve this problem to work properly?
#8

[eluser]TheFuzzy0ne[/eluser]
You can just enable the profiler by putting this into your controller constructor:
Code:
$this->output->enable_profiler(TRUE);

This will (among other things) show you the query that's generated, so you can fire it straight at the database yourself (using the CLI, PHPMyAdmin or whetever else tickles your fancy), and see if you get any results back.
#9

[eluser]linderox[/eluser]
o no... It's not working. I said this because I see something. it was error. But it's not show any data from db




Theme © iAndrew 2016 - Forum software by © MyBB