我不知道为什么我CI
从phpMyAdmin
Model返回错误的值:
<?php
class Post extends CI_Model
{
function __construct()
{
parent::__construct();
}
function getallpost()
{
return $this->db->get('post');
}
}
?>
和
控制器 :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Postc extends CI_Controller {
function index()
{
$this->load->model('post');
$posts=$this->post->getallpost();
echo '<pre>';
print_r($posts);
}
}
?>
你的代码没有给你任何错误,它正在做你要求它做的事情。也许您需要具体说明您想要获得的信息。你在你的模型中看到
function getallpost()
{
return $this->db->get('post');
}
上面的函数将返回一个对象。如果你想得到一个数组,你需要写
return $this->db->get('post')->result_array();
并确保您的帖子表中有一些数据要打印要了解有关查询数据库的更多信息,您应该阅读 Codeigniter 的Query Builder Class
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句