0

出力を取得するためにjson配列を使用して、同じ名前を持つdbからデータを取得する必要があります。

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)
        {
             $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;

    }

0出力:

出力を次のように取得する必要があります

<data>
      <_0/>
      <message>Review details retrieved successfully.</message>
      <reviewee_name>deepi</reviewee_name>
      <reviewer_id>4</reviewer_id>
      <tournament_played_c_s>karnataka,bangalore</tournament_played_c_s>
   </data>
<data>
      <_1/>
      <message>Review details retrieved successfully.</message>
      <reviewee_name>deepi</reviewee_name>
      <reviewer_id>5</reviewer_id>
      <tournament_played_c_s>kerala</tournament_played_c_s>
   </data>

これで何を変更する必要がありますか?

4

1 に答える 1

0

これは機能しますか?

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();
    // Check if query succeeded
    if ($query !== false) {
        $row_counter = 0;
        // Loop through all results returned
        while ($row = $query->result())
        {
            $data[$row_counter]['reviewer_id'] = $row->reviewer_id;
            $data[$row_counter]['reviewee_name'] = $row->reviewee_name;
            $data[$row_counter]['tournament_played_c_s'] = $row->tournament_played_c_s;
            $data[$row_counter]['message'] = 'Review details retrieved successfully.';
            $row_counter++;
        }
        $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-09T10:22:07.380 に答える