codeIgniter获取结果的问题

时间:2013-09-15 03:30:44

标签: php mysql sql codeigniter

我正在尝试显示仅记录在用户区域的邮政编码。

要获取用户区域,get_zipcode()拨打get_area_name()

但是,如果我从500 error获得价值,则会get_area_name()

如果我注释掉了get_area_name()并添加了加密的编码值$area ="ny",那就可以了。

我认为get_area_name()存在一些问题。

area”的表格如下:

CREATE TABLE IF NOT EXISTS `wn_area` (
  `area_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `area` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`area_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=165 ;

功能

    public function get_zipcode($area_id)
    {
        $this->db->select("*");

        $this->db->from("zipcode");

        if ($area_id != "" )
        {
            $ar_area_ids = array(1,2,3,4,5,6,7,8);

            //$area = get_area_name($area_id);
            $area = "ny";

            if( in_array($area_id, $ar_area_ids) ){
                $this->db->like('sido', $area); 
            }else {
                $this->db->like('gugun', $area);
            }

        }else{  

            $this->db->like("sido", 'ny'); 
            $this->db->limit("10000");
        }


        $this->db->order_by("zipcode_id");

        $query = $this->db->get();

        return ($query->num_rows() > 0) ? $query->result() : FALSE;
    }

  public function get_area_name($area_id)
    {
        $this->db->select("*");

        $this->db->from("area");

     $this->db->where("area_id", $area_id);

        $query = $this->db->get();

        return $query->row()->area;

    }

1 个答案:

答案 0 :(得分:1)

由于它的类要从类中的另一个方法调用方法,你需要使用$this,比如,更改:

$area = get_area_name($area_id);

$area = $this->get_area_name($area_id);