【发布时间】:2017-09-07 11:56:44
【问题描述】:
我是 codeigniter 的新手,并试图将百分比结果输出到我的项目的 codeigntier 视图中。一旦我解决了这个问题,事情就会顺利得多。 他是模型函数:
<?php
public function _construct()
{
$this->load->database();
}
public function percent_specilation1($numstudent)
{
$query = $this->db->query("SELECT * FROM Student WHERE Student.JRNOption ='1'");
$numstudent = $query->num_rows()/25;
if($query->num_rows() > 0){
return $numstudent;
}
return null;
}
?>
这里是控制器。
<?php
class Statscontroller extends CI_Controller {
public function _contruct(){
parent::_construct();
$this->load->model('Stats_model');
}
public function index(){
//echo "Various stats for the Journalism department:";
$data['Test'] = $this->Stats_model->percent_specilation1($numstudent);
}
public function view($page = 'Statsview')
{
if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
//$data['title'] = ucfirst($page);
$this->load->view('templates/header',$data);
$this->load->view('Statscontroller/index',$data);
$this->load->view('templates/header');
}
?>
Here is the view
<html>
<h1> Various Statistics for the Journalism department</h1>
<?php
echo "Percent of students that are undecided:";
echo $Test; ?>
</html>
我做错了什么?我试图让它正确一个多小时,我只想从数据库查询中输出单个结果。您可以提供的任何帮助都会很棒..请尊重。谢谢!
【问题讨论】:
-
问题可能出现在您的索引中,然后添加 $this->view() 以显示您创建的视图。
-
模型看起来根本不像 CI。你可能误解了这个框架。请浏览文档。
标签: php html sql codeigniter view