Codeigniter를 사용하여 데이터베이스에서 데이터를 생성하는 간단한 간단한 코드를 만들었습니다. 데이터가 내 시각에 표시되고 있지만 문제가 있습니다. 각 레코드는 9 번 생성되었습니다. 예 이름이 John Doe 인 이메일 ID가 데이터베이스인데 [email protected], 생년월일 : xxxx-xx-xx는 9 번 반복되었습니다.누구나이 foreach 루프에 문제가 있습니까?
<?php
class Transaction extends CI_Model
{
function getdata()
{
$this->db->select('name, email, schools_name');
$this->db->from('employee, schools');
$r = $this->db->get();
return $r;
}
}
컨트롤러 :
<?php
class Layer extends CI_Controller
{
function index()
{
$this->load->model('transaction');
$data['data'] = $this->transaction->getdata();
$data['title'] = 'This is title';
$this->load->view('test', $data);
}
}
그리고보기 :
<!DOCTYPE html>
<html>
<head>
<title>Check</title>
</head>
<body>
<?php
echo heading($title, 1);
foreach (($data->result()) as $row)
{
echo '<p>Name: ' . $row->name . 'and <br> Email: ' . $row->email . '<br> Schools: '.$row->schools_name.'</p>';
}
?>
</body>
</html>
어쩌면 내가이의 원인이 무엇인지 난 그냥 캔트 발견 너무 피곤 해요 여기
모델이다. : D
많은 감사,
편집 :
array(1) { [0]=> object(stdClass)#20 (3) { ["name"]=> string(16) "Braxton Amundson" ["email"]=> string(18) "[email protected]" ["schools_name"]=> string(21) "Penn State University" } }
데이터 란 무엇입니까? 그것은 배열 또는 객체입니까? 컨트롤러의 배열처럼 사용하고 있지만 뷰의 객체입니다. – AgmLauncher
괄호 안에'$ data-> result()'가있는 이유는 무엇입니까? – Anthony
이게 뭐지?'$ this-> db ('$ data-> result()'는 왜'$ data-> result – Ghost