您好,我正在为一个项目使用codeigniter框架,我有一个控制器,它从一个模型函数调用数据。这是控制器。

  public function getThirdPartyRR($token){
    if ($this->input->is_ajax_request()){
        // $data = json_decode(file_get_contents('php://input'), true);
        // Following is loaded automatically in the constructor.
        //$this->load->model('user_profile');
        $userid = $this->myajax->getUserByAuth($token);
        if ($userid){
            $this->load->model("riskrating_page");
            /* If we have an impersonated user in the session, let's use him/her. */
            if (isset($_SESSION['userImpersonated'])) {
                if ($_SESSION['userImpersonated'] > 0) {
                    $userid = $_SESSION['userImpersonated'];
                }
            }
            // $resultList value could be null also.
            $result = $this->riskrating_page->getThirdPartydata($userid);
            /* Little bit of magic :). */
            $thirdpartylist = json_decode(json_encode($result), true);
            $this->output->set_content_type('application/json');
            $this->output->set_output(json_encode($thirdpartylist));
        } else {
            return $this->output->set_status_header('401', 'Could not identify the user!');
        }
    } else {
        return $this->output->set_status_header('400', 'Request not understood as an Ajax request!');
    }
}

这是模型中的查询函数,我从中获取数据。
function getThirdPartydata($id){

      $query = 'SELECT b.text_value as Company, a.third_party_rr_value
                FROM user_thirdparty_rr a
                inner join text_param_values b
                    on a.third_party_rr_type = b.text_code and
                    b.for_object = \'user_thirdparty_rr\'
                WHERE a.Owner = '.$id. ' and
                    a.UPDATE_DT is null;';

    }

但当我使用netbeans调试它时,它显示在$result函数的控制器中,我得到了空值,这意味着我无法从mysql获取任何数据。
这是mysql的搜索结果。php - 无法从mysql查询到 Controller 获取数据-LMLPHP

最佳答案

您只编写查询而不从查询结果中获取任何数据

function getThirdPartydata($id){

      $query = "SELECT b.text_value as Company, a.third_party_rr_value
            FROM user_thirdparty_rr a
            inner join text_param_values b
                on a.third_party_rr_type = b.text_code and
                b.for_object = 'user_thirdparty_rr'
            WHERE a.Owner = '$id' and
                a.UPDATE_DT is null";
             $this->db->query($query);// execute your query
             return $query->result_array();// fetch data

    }

08-04 16:31