简体   繁体   English

codeIgniter获取结果的问题

[英]issue with codeIgniter fetching result

I'm trying to display zipcode which only logged in user's area. 我正在尝试显示仅登录用户区域的邮政编码。

To get user's area, get_zipcode() calls get_area_name() . 要获取用户区域, get_zipcode()调用get_area_name()

But, there is 500 error if I get value from get_area_name() ; 但是,如果我从get_area_name()获取值, get_area_name()出现500 error

If I commented out get_area_name() and put harded coded value $area ="ny" , it works. 如果我注释掉get_area_name()并放入硬编码值$area ="ny" ,它就可以工作。

I think there is some issue with get_area_name() . 我认为get_area_name()有问题。

table for " area " is following 以下是“ 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 ;

Function 功能

    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;

    }

since its class to call method from another method inside class , you need to use $this , like, change: 因为它的类从类中的另一个方法调用方法,所以您需要使用$this ,例如,change:

$area = get_area_name($area_id);

to

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM