• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cannot load data from database, the result is blank screen

#1
[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>';
}

}

}
?&gt;

view : index.php on display folder.

&lt;?php
$this->load->view("header");
?&gt;
<h2>&lt;?= $title; ?&gt;</h2>

<div id="function_description">
&lt;?= $display_data;?&gt;
</div>
&lt;?
$this->load->view("footer");
?&gt;

so, I hope everyone can help me...coz, I'm newbie on CI...thanks for your kind help & support.

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

#3
[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)?

#4
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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