我从mysql数据库中提取国家名称时哪里出错了?
(codeigniter: activerecord enabled)
它打印出“默认国家”而不是预期的“澳大利亚”。
页面控制器
public function view($page)
{
$page = strtoupper($page); // Capitalize the first letter
$data = array(
'title' => 'My Title',
'country' => 'default country'
);
$this->getCountryName($page, $data);
if(!is_null($data['country'])){
$page = "country";
}
$this->load->helper('url');
$this->load->helper('utility');
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
if(!is_null($data['country'])){
$this->load->view('templates/infobox', $data);
}
$this->load->view('templates/footer', $data);
}
function getCountryName(&$page, &$data){
$this->db->select('name')->from('pv_country')->where('code', $page);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
$data['country'] = $row;
echo $row;
}
}
}
乡村景观
<div style =" position:absolute;top:90%; background: red;">
<?php echo $country; ?></div> // prints default country.
</div>
遇到 PHP 错误
严重性:4096
消息:stdClass 类的对象无法转换为字符串
文件名:pages/country.php
行号:25