同じ名前の名前が複数ある場合、名前を検索すると1つの結果が返されます。これはforeachループである可能性がありますが、activerecordステートメントだと思います。
モデル
public function finduser($name) {
if ($name == null || $name == '') {
return false;
}
$this->db->select('e.emp_no, e.first_name, e.last_name, t.title, d.dept_no');
$this->db->from('employees AS e, titles AS t, dept_emp AS d');
$this->db->where('e.last_name', $name);
$this->db->where('e.emp_no = t.emp_no');
$this->db->where('e.emp_no = d.emp_no');
$result = $this->db->get();
$data = array();
foreach ($result->result() as $row )
{
$entry = array();
$entry['emp_no'] = $row->emp_no;
$entry['first_name'] = $row->first_name;
$entry['last_name'] = $row->last_name;
$entry['title'] = $row->title;
$entry['dept_no'] = $row->dept_no;
$data[] = $entry;
return $data;
}
}
見る
if (isset($user)) {
foreach ($user as $res) {
echo "employee id =" .$res['emp_no']; ?> <br> <?php
echo "first name = " .$res['first_name']; ?> <br> <?php
echo "last name = " .$res['last_name']; ?> <br> <?php
echo "title = " .$res['title']; ?> <br> <?php
echo "department no = " .$res['dept_no']; ?> <br><br> <?php