mysql 데이터베이스에서 국가 이름을 추출 할 때 어디에서 잘못되고 있습니까?
(codeigniter : activerecord 활성화 됨)
예상되는 "호주"대신 "기본 국가"를 인쇄합니다.
페이지 컨트롤러
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
그래서 더 많은 디버깅을 넣고 결과를 얻기 위해 호출 할 올바른 구문 / 메소드를 찾은 다음 뷰에서 액세스해야하는 속성이있는 객체를 반환합니다.
function getCountryName(&$page, &$data){
$this->db->select('name')->from('pv_country')->where('code', $page);
$query = $this->db->get();
if ($query->num_rows() > 0)
{
$data['country'] = $query->row();
}
}
<?php echo $country->name; ?>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다