我正在尝试使用数据库中的值对数组进行计数。为什么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] 删除。
我来说两句