0

I'm unable to view data from my database using these codes. Just echoing NO Records Returned

controller :

 public function get_task()
    {
        $data = array();

        if( $query = $this->model_users->getTask()){
            $data ['records'] = $query ;
        }

        $this->load->view('Reg_Login/members', $data);
    }

members.php :

<?php if(isset($records)) : foreach($records  as $row): ?>

<tr>
<td><?php echo $row->tname ;?></td>
<td><?php echo $row->time; ?> </td>
</tr>

<?php endforeach; ?>

<?php else : ?>
<h2>No Records Returned</h2>
<?php endif; ?>

model_users :

public function getTask()
      {
         $query = $this->db->get('tasks');
         return $query->result();
       } 
6
  • whats in your log? are there are erros? any apache logs? also try looking into mysql query log to see if any query is being executed. Commented Apr 21, 2015 at 18:44
  • @unixmiah There are no errors. The query inside <?php else :?> were executed which is No Records Returned. Check my view file's last para. Commented Apr 21, 2015 at 18:47
  • why are you using : with else statement. use { for your if else block. and add $this->output->enable_profiler(TRUE); on top of your method and check what query is being executed. Commented Apr 21, 2015 at 18:59
  • The {} aren't necessary. <?php if(condition): ?> <HTML CODE> <?php else: ?> <DIFFERENT HTML CODE> <?php endif; ?> Works perfectly fine. It looks cleaner too. Commented Apr 21, 2015 at 19:05
  • @KamranAdil Yap @Cro is right but thanks to your idea of adding $this->output->enable_profiler(TRUE); It helped me out to find what query was executing and I found that I didn't invoke the method properly. Now my problem is solved. Thank you guys for your efforts ! :) Commented Apr 21, 2015 at 19:33

1 Answer 1

1

There was no error in the code.

By using $this->output->enable_profiler(TRUE); in my controller I found that, I just didn't invoke my method properly.

That's all, you can use these codes to fetch data from DB and show in your view file.

Sign up to request clarification or add additional context in comments.

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.