데이터베이스의 값을 사용하여 배열을 계산하려고합니다. PHP는 왜 하나만 반환합니까? 모든 값을 반복해야합니까?
// count the amount of users to display
public function count_users()
{
$data = array();
$this->db->select("id","username");
$this->db->order_by("username","asc");
$query = $this->db->get("users");
if ($query->num_rows() > 0)
{
$data = $query->row_array();
echo count($data); // here we echo out the count / num of users. it only displays 1 instead of the correct value, 3
}
return $data;
}
이것도 시도해 볼 수 있습니다.
codeigniter를 사용하고 있으므로 아래 코드로 사용자 레코드 수를 확인할 수 있습니다.
echo $query->num_row();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다