Codeigniter选择始终返回顶行数据

时间:2014-07-03 13:56:09

标签: php mysql codeigniter

我正在尝试从cus mobile获取tbl_customer_registration cus_email $email $email

换句话说,我希望客户移动 客户电子邮件等于$this->db->select("tbl_customer_registration.cus_mobile"); $this->db->from('tbl_customer_registration'); $this->db->where('tbl_customer_registration.cus_email', $email); $query = $this->db->get(); if ($query->num_rows() > 0) { return $query->row_array(); } else { return NULL; }

tbl_customer_registration.cus_mobile

enter image description here

它始终返回 Array ( [session_id] => ecf905ab051376563d3ce4140716d818 [ip_address] => ::1 [user_agent] => Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0 [last_activity] => 1404446526 [user_data] => [mobile] => 0712641946 [user_name] => podijobs@gmail.com [is_logged_in] => 1 [cart_contents] => Array ( [66eeaa0e65f3bf68db770c4c1b29891e] => Array ( [rowid] => 66eeaa0e65f3bf68db770c4c1b29891e [id] => SP004 [qty] => 1 [price] => 1500 [name] => Vegi Pizza Big [image] => pizza-buena.jpg [subtotal] => 1500 ) [total_items] => 1 [cart_total] => 1500 ) )

的第一行

以下是他们返回的内容,不是我需要的cus_mobile

{{1}}

1 个答案:

答案 0 :(得分:1)

您需要使用函数result()或result_array()才能返回如下查询结果:

foreach ($query->result_array() as $row)
{
   echo $row['cus_mobile'];
}

如果您希望只返回一行,您还可以使用函数row(),如:

if ($query->num_rows() > 0)
{
  $row = $query->row();
  echo $row->cus_mobile;
}