Php 资源(29,mysql链接持久)
当我使用var_dump$行时;在我的代码中,一行应用程序在网页上说resource29,mysql链接持久化这意味着什么?我是php和codeignite的新手,所以如果可以的话请简化,非常感谢 controller.phpPhp 资源(29,mysql链接持久),php,codeigniter,pagination,Php,Codeigniter,Pagination,当我使用var_dump$行时;在我的代码中,一行应用程序在网页上说resource29,mysql链接持久化这意味着什么?我是php和codeignite的新手,所以如果可以的话请简化,非常感谢 controller.php <?php class Survay extends CI_Controller{ function index() { $data = array( 'question' => $this->input->
<?php
class Survay extends CI_Controller{
function index()
{
$data = array(
'question' => $this->input->post('question'),
'answer1' => $this->input->post('answer1'),
'answer2' => $this->input->post('answer2'),
'answer3' => $this->input->post('answer3'),
'answer4' => $this->input->post('answer4'),
'answer5' => $this->input->post('answer5'),
'answer6' => $this->input->post('answer6'),
);
if($query = $this->membership_model->get_records()){
$data['records'] = $query;
}
$this->page();
$this->load->view('survay_view', $data);
}
//pagination
function page()
{
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/admin/index.php/survay/';
$config['total_rows'] = $this->db->get('save_survay')->num_rows();
$config['per_page'] = 1;
$config['num_links'] =10;
$this->pagination->initialize($config);
//print_r($this->uri->segment());die;
$data['records'] = $this->db->get('save_survay', $config['per_page'],
$this->uri->segment(2,0));
$data['pagination'] = $this->pagination->create_links();
$this->load->view('survay_view', $data);
}
}
?>
view.php
</head>
<body>
<h1>Answer</h1>
<?php if (isset($records)) : foreach($records as $row) : ?>
<div = 'container'>
<ul>
<?php
if (isset($pagination))
{
echo $pagination;
}
?>
<h1><?php echo $row->question; ?></h1>
<li><?php echo $row->answer1; ?></li>
<li><?php echo $row->answer2; ?></li>
<li><?php echo $row->answer3; ?></li>
<li><?php echo $row->answer4; ?></li>
<li><?php echo $row->answer5; ?></li>
<li><?php echo $row->answer6; ?></li>
<ul>
</div>
<?php endforeach; ?>
<?php else : ?>
<h2>no records were returned</h2>
<?php endif; ?>
</body>
</html>
注意消息:尝试获取非对象文件名的属性:views/survay_view.php行号:33
收到上述错误的原因是,您试图访问$records数组中作为对象$row->some_变量保存的数据,而该数据似乎不是对象
您正在使用以下代码从数据库中获取结果:
$data['records']=$this->db->get'save\u survay',$config['per\u page'],$this->uri->segment2,0
上面的代码在数据库上运行一个查询,但这本身并不能生成任何有用格式的结果。它返回的是一个数组,包含与查询有关的各种数据,其中包含结果
要作为对象访问结果,可以按如下方式调整代码:
$data['records']=$this->db->get'save_survay',$config['per_page'],$this->uri->segment2,0->result
如果希望将结果作为数组返回,可以使用以下命令:
$data['records']=$this->db->get'save\u survay',$config['per\u page'],$this->uri->segment2,0->result\u数组
正如我在评论中提到的,我真的建议阅读文档,特别是关于的页面,你能发布你的代码片段吗?我一直收到一个错误,说遇到了PHP错误严重性:注意消息:试图获取非对象文件名的属性:views/survay_view.PHP行号:33上面的代码有几个问题。首先,您的数据库代码$this->db->get位于控制器中。为了遵守MVC编程方法,应该将此代码放在模型中。它不会破坏您的代码,但会帮助您分离代码并使其更易于管理。出现上述错误的问题是,您需要使用$this->db->get->result返回一个results对象。我建议您阅读codeigniter文档,特别是这一页:该文档有多种语言可供使用,您可以详细介绍这些错误吗?非常感谢你的帮助,你让我免于了很多麻烦:我现在正在阅读这份文件