cannot load data from database, the result is blank screen |
[eluser]Unknown[/eluser]
Hai...everyone. I cannot display my data from database but blank screen displayed. I think my code (conttroler,view & model) is right...but, i dont know what wrong. this screenshoot my code: controller : display.php <?php class Display extends Controller { function Display() { parent::Controller(); $this->load->model('display_model'); $this->output->cache(120); } function index() { $data['title'] = "Data on Database"; $data['display_data'] = $this->display_model->SelectData(); //"data"; $this->load->view('display/index',$data); } } ?> model : display_model.php <?php class Display_model extends Model { function Display_model() { parent::Model(); } function SelectData() { $this->db->orderby('function_name'); $this->db->limit(10); $query = $this->db->get('function'); if ($query->num_rows > 0) { $output = '<table>'; $output. = '<tr><td>Function Name</td><td>Function Description</td></tr>'; foreach ($query->result as $row) { $output. = '<tr><td>'.$row->function_name.'</td>'; $output. = '<td>'.$row->function_description.'</td></tr>'; } $output. = '</table>'; return $output; } else { return '<p>Sorry, no results returned.</p>'; } } } ?> view : index.php on display folder. <?php $this->load->view("header"); ?> <h2><?= $title; ?></h2> <div id="function_description"> <?= $display_data;?> </div> <? $this->load->view("footer"); ?> so, I hope everyone can help me...coz, I'm newbie on CI...thanks for your kind help & support.
[eluser]einstein[/eluser]
Try this: $this->Display_model->SelectData(); also change this foreach ($query->result as $row) to foreach ($query->result() as $row) Let me know if it works
[eluser]Seppo[/eluser]
Same thing happens with num_rows. although you still should be seeing your title or the sorry message. Do you have display_errors on or off (take a look at your phpinfo)?
[eluser]Unknown[/eluser]
@Einstein thanks you for your response. I also changed my code as your suggest (thanks for correction, I think mistyping code). but I still got blank screen. actualy, I don't know what happens???. @seppo I have activate my display_error, and I got error message why it cannot works like this Parse error: syntax error, unexpected '=' in C:\apache2triad\htdocs\tutorial\system\application\models\display_model.php on line 20 I have revised my code, but it still not works. I don't know what wrong? I attach my screnshoot-code which write with italic to this post. function Display_model() { parent::Model(); } function SelectData() { $this->db->orderby('function_name'); $this->db->limit(10); $query = $this->db->get('function'); if ($query->num_rows() > 0) { //$output = '<table>'; //$output. = '<tr><td>Function Name</td><td>Function Description</td></tr>'; foreach ($query->result() as $row) { $output = $row->function_name; $output. = $row->function_description; } //$output. = '</table>'; return $output; } else { return '<p>Sorry, no results returned.</p>'; } overall, thanks for kindly help. I hope you response my post-issue |
Welcome Guest, Not a member yet? Register Sign In |