0

table is not displaying any value in table. When i did var_dump($results). It printed NULL. Since, i am new to codeigniter, i am not able to solve this problem. I'm not getting, where i did mistake. Help Me.

View Page

 <tbody>
                    <?php
                    if(!empty($results) ) {
                        foreach($results as $row) {
                        echo '<tr>';
                        echo '<td>'." ".'</td>';
                        echo '<td>'.$row->FileTitle.'</td>';
                        echo '<td>'.$row->UploadedFile.'</td>';
                        echo '<td>'.$row->CreationDate.'</td>';
                        echo '<td>'.$row->UpdateDate.'</td>';
                        echo '<td>'." ".'</td>';
                        echo '</tr>';
                        }
                    }?>
                </tbody>

Controller

class Welcome extends CI_Controller {
public function __construct()
        {
                parent::__construct();
                $this->load->model('news_model');

        $this->load->helper('form');
        $this->load->library('form_validation');

        }
public function member_CAttachments()
    {
         $data['results'] = $this->news_model->member_MAttachments(); 
         $this->load->view('member/templates/header');
         $this->load->view('member/index',$data);
         $this->load->view('member/templates/footer');
        }
}

Model

class News_model extends CI_Model 
{

        public function __construct()
        {
                $this->load->database();
        }
     public function member_MAttachments()
    {
        $results = array();

            $query = $this->db->get('MemberFileDetails');

            if($query->num_rows() > 0)
        {
                $results = $query->result();
            }

            return $results;
    }
}
5
  • I think you are not getting any result from your query!!check result present in your database or not!! Commented Aug 21, 2015 at 9:57
  • remove $results = array();. its just a suggestion. try it. Commented Aug 21, 2015 at 9:58
  • $data['results'] print in controller and check that you are getting any result or not also $query->num_rows() print it Commented Aug 21, 2015 at 9:58
  • Also if no result found return false Commented Aug 21, 2015 at 10:01
  • @syedmohamed: yeah. thank you. got it. Sorry all, i wasted all your time. In url, some different view was getting called. i didn't saw that. Just now, i discovered it. i changed to localhost/Project/index.php/welcome/member_CAttachments Previously it was localhost/Project/index.php/welcome/check_login So, i changed code their in check_login controller. I made it redirect to this page. Thank You Everyone. Sorry For Wasting all your important time. Embarass. Commented Aug 21, 2015 at 10:08

3 Answers 3

1

Instead you can do it in fewer lines with inbuilt CI Table library,

supports both 2.2 and 3.x versions.

Use it like,

$this->load->library('table');

$this->table->set_heading('FileTitle', 'UploadedFile', 'CreationDate', 'UpdateDate');

$query = $this->db->query('SELECT * FROM MemberFileDetails');

echo $this->table->generate($query);
Sign up to request clarification or add additional context in comments.

1 Comment

Wow. Is it. Nice. Let me use this. Thank you.
0

do you have records in your table ? if yes then please try to remove the

if($query->num_rows() > 0) condition in the model and try.

Comments

0

remove $results = array(); in your code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.