数据库数据不显示plz解决了这个问题 [英] Database data not display plz solve this

查看:104
本文介绍了数据库数据不显示plz解决了这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

home.php

 <?php  
defined(' BASEPATH')或退出(' 不允许直接访问脚本');

class 主页扩展CI_Controller {


公共函数索引()
{
$ this-> load-> view(' home');
}

公共职能课程(){
$ course = $ this-> db-> get (' course');
$ data [' records'] = $ course-> result_array();
$ this-> load-> view(' course / course',$数据);
}

公共职能course_add_view(){
$ this-> load-> view(' < span class =code-string> course / course-add');
}

公共职能course_edit_view(){
$ id = $ this-> uri-> segment (' 3');
$ this-> db-> where(' id',$ id) ;
$ course = $ this-> db-> get(' 当然');
$ data [' records'] = $ course-> result_array();
$ this-> load-> view(' course / course-edit' ,$ data);
}

公共职能course_delete(){
$ id = $ this-> uri-> segment (' 3');
$ this-> load-> model( course);
$ check = $ this-> course-> delete($ id);
if($ check){
redirect( home / course) ;
} 其他 {
echo 记录失败;
}
}

public function course_add(){
/ * echo< pre>;
print_r($ _ POST); * /

$ data = $ this-> input-> post();
unset($ data [' submit']);
// print_r($ data);
$ this-> load - > model( course);
$ check = $ this-> course-> insert($ data);
if($ check){
redirect( home / course) ;
} 其他 {
echo 记录失败;
}

}

公共职能course_edit(){
/ * echo< pre>;
print_r($ _ POST); * /

$ data = $ this-> input-> post();
$ id = $ this-> input-> post(' ID );
unset($ data [' submit']);
// print_r($ data);
$ this-> load - > model( course);
$ check = $ this-> course-> update($ data,$ id);
if($ check){
redirect( home / course) ;
} 其他 {
echo 记录失败;
}

}

// 学生

公共职能学生(){
$ course = $ this-> db-> query(< span class =code-string>
select student.id,student.surname,student.name,student.city,student.gender,student.bdate,course来自学生的.sname,其中'student' 'course-id'= course.id );
$ data [' records'] = $ course-> result_array();
$ this-> load-> view(' student / student',$数据);
}

}



student.php

 <?php 定义
' BASEPATH')退出(' 不允许直接访问脚本'); ?>
< !DOCTYPE html >

< meta charset = utf-8 >
< title > WEL来到CodeIgniter

< div class = container >
< h2 > 学生< / h2 >
< div class = < span class =code-keyword> table-responsive
>

<? php
foreach($ records as $ row){
echo ;
echo ;
echo ;
echo ;
echo ;
if($ row [' gender'] == M){
$ row [' gender'] = 男性;
} else {
$ row [' 性别] = 女性;
}
echo ;
echo ;
echo ;
echo ;
echo ;
echo ;
}
?>
< class = table > < thead > < tr > < th > < / th > < th > 课程< / th > < th > ; 名称< / th > < th > < / th > < th > 性别< / th > < th > 城市< / th > < th > 出生日期< < span class =code-leadattribute> / th
> < / tr > < / thead > < tbody > < tr > < td > ; 。$ row ['id']。< / td > < td > 。$ row ['sname']。< / td > < td > 。$ row ['name']。< / td > < td > 。$ row ['surname']。< / td > < td > 。$ row ['gender']。< / td > < td > 。$ row ['city']。< / td > < td > 。$ row ['bdate']。< < span class =code-leadattribute> / td
> < td > < a href = .base_url()。index.php / home / course_delete /\".$ row [ > ; 删除< / a > < / td > < td > < span class =code-keyword>< a href = .base_url()。index.php / home / course_edit_view /\".$ row [ > 编辑< / a > < / td > < ; / tr > < / tbody > < / table >
< / div >
< ; / div >



没有错误但它没有显示数据库数据....只显示这样的标题....

学生

#课程名称姓氏性别城市出生日期



我尝试过:



没有错误来了,但它没有显示数据库数据....只显示这样的标题....

学生

#课程名称姓氏性别城市出生日期

解决方案

this-> load-> view(' home'< /跨度>);
}

公共职能课程(){


course =


this-> db-> get(' course');

home.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {


	public function index()
	{
		$this->load->view('home');
	}
	
	public function course() {
		$course = $this->db->get('course');
		$data['records'] = $course->result_array();
		$this->load->view('course/course', $data);
	}
	
	public function course_add_view() {
		$this->load->view('course/course-add');
	}
	
	public function course_edit_view() {
		$id = $this->uri->segment('3');
		$this->db->where('id', $id);
		$course = $this->db->get('course');
		$data['records'] = $course->result_array();
		$this->load->view('course/course-edit', $data);
	}
	
	public function course_delete() {
		$id = $this->uri->segment('3');
		$this->load->model("course");
		$check = $this->course->delete($id);
		if($check) {
			redirect("home/course");
		} else {
			echo "Record Failed";
		}
	}
	
	public function course_add() {
		/*echo "<pre>";
		print_r($_POST);*/
		$data = $this->input->post();
		unset($data['submit']);
		//print_r($data);
		$this->load->model("course");
		$check = $this->course->insert($data);
		if($check) {
			redirect("home/course");
		} else {
			echo "Record Failed";
		}

	}
	
	public function course_edit() {
		/*echo "<pre>";
		print_r($_POST);*/
		$data = $this->input->post();
		$id = $this->input->post('id');
		unset($data['submit']);
		//print_r($data);
		$this->load->model("course");
		$check = $this->course->update($data, $id);
		if($check) {
			redirect("home/course");
		} else {
			echo "Record Failed";
		}

	}
	
	//students
	
	public function student() {
		$course = $this->db->query("select student.id, student.surname, student.name, student.city, student.gender, student.bdate, course.sname from student, course where 'student'"."'course-id' = course.id");
		$data['records'] = $course->result_array();
		$this->load->view('student/student', $data);
	}
	
}


student.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');?>
<!DOCTYPE html>

	<meta charset="utf-8">
	<title>Welcome to CodeIgniter

	<div class="container">
	<h2>Student</h2>
		<div class="table-responsive">
        	
            	                	<?php
					foreach($records as $row) {
						echo "";
                    	echo "";
                        echo "";
                        echo "";
                        echo "";
						if($row['gender']=="M") {
							$row['gender'] = "Male";
						} else {
							$row['gender'] = "Female";
						}
						echo "";
						echo "";
						echo "";
						echo "";
						echo "";
                    	echo "";
					}
				?>
                <table class="table"><thead>                	<tr>                    	<th>#</th>                        <th>Course</th>                        <th>Name</th>                        <th>Surname</th>                        <th>Gender</th>                        <th>City</th>                        <th>Birth Date</th>                    </tr>                </thead>                <tbody><tr><td>".$row['id']."</td><td>".$row['sname']."</td><td>".$row['name']."</td><td>".$row['surname']."</td><td>".$row['gender']."</td><td>".$row['city']."</td><td>".$row['bdate']."</td><td><a href="".base_url()."index.php/home/course_delete/".$row[">Delete</a></td><td><a href="".base_url()."index.php/home/course_edit_view/".$row[">Edit</a></td></tr></tbody>            </table>
		</div>
	</div>


no error come but its not shown database data....only header shown like this....
Student
# Course Name Surname Gender City Birth Date

What I have tried:

no error come but its not shown database data....only header shown like this....
Student
# Course Name Surname Gender City Birth Date

解决方案

this->load->view('home'); } public function course() {


course =


this->db->get('course');


这篇关于数据库数据不显示plz解决了这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆