0
function search_review($input, $serviceName){
        $ipJson = json_encode($input);
        $this->db->select('*');
        $this->db->from('reviews');
        $this->db->where('reviewee_name', $input['reviewee_name']);
        $query = $this->db->get();
        $result = $query->result();
        if (!empty($result)) {
        foreach ($query->result() as $row)
        {
            $data['reviewer_id'] = $row->reviewer_id;
            $data['reviewee_name'] = $row->reviewee_name;
            $data['tournament_played_c_s'] = $row->tournament_played_c_s;
        }
            $data['message'] = 'Review details retrieved successfully.';
            $status = $this->clamo_lib->return_status('success', $serviceName, $data, $ipJson);
        } else {
            $data['message'] = 'Unable to retrieve review details.';
            $status = $this->clamo_lib->return_status('error', $serviceName, $data, $ipJson);
        }
        return $status;
    }

这是我的代码,我可以检索具有相同名称的单行数据。例如 reviewee_name="sangeetha" 意味着我需要显示名称为 sangeetha 的详细信息。但现在只有单行数据我得到了我需要做的事情?

4

2 回答 2

0
<?php

//don't overwrite the array values
function search_review($input, $serviceName){

    $data = array();

    $ipJson = json_encode($input);
    $this->db->select('*');
    $this->db->from('reviews');
    $this->db->where('reviewee_name', $input['reviewee_name']);
    $query = $this->db->get();
    $result = $query->result();
    if (!empty($result)) {
        foreach ($query->result() as $row)
        {
            //here you're overwriting the values
            $data[]['reviewer_id'] = $row->reviewer_id;
            $data[]['reviewee_name'] = $row->reviewee_name;
            $data[]['tournament_played_c_s'] = $row->tournament_played_c_s;
        }
        $data['message'] = 'Review details retrieved successfully.';
        $status = $this->clamo_lib->return_status('success', $serviceName, $data, $ipJson);
    } else {
        $data['message'] = 'Unable to retrieve review details.';
        $status = $this->clamo_lib->return_status('error', $serviceName, $data, $ipJson);
    }
    return $status;
}
于 2013-07-09T07:41:48.707 回答
0

看着你的代码..我可以看到你正在替换数据数组中的相同键..所以这就是问题..

尝试这个

..
foreach ($query->result() as $row)
{
        $data[]['reviewer_id'] = $row->reviewer_id;
        $data[]['reviewee_name'] = $row->reviewee_name;
        $data[]['tournament_played_c_s'] = $row->tournament_played_c_s;
 }
...

这不会替换键..但是 $data 将具有不同的结构(二维数组),所以在显示它时要小心..echo "<pre>";print_r($data);用于检查 $data 结构

于 2013-07-09T07:42:23.293 回答